[Gtk-sharp-list] struct changes patch

Vladimir Vukicevic vladimir@pobox.com
05 Nov 2002 21:22:02 -0800


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


This patch changes struct generation to use a static "Zero" member to
represent null structs, similar to the way the IntPtr struct does it. 
This makes all structs identical in layout to the C versions. 

Also included here are changes to GtkClipboard and GtkSelectionData, to
make these work in a c# environment; these changes depend on the struct
changes above (since there are some structs where refs need to be passed
to callbacks).

	- Vlad

-- 
Vladimir Vukicevic <vladimir@pobox.com>

--=-d6IWdtLLuS8DypcXo63E
Content-Disposition: attachment; filename=gtksharp-struct.patch
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=gtksharp-struct.patch; charset=ANSI_X3.4-1968

diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/generator/CallbackGen.cs gtk-s=
harp/generator/CallbackGen.cs
--- orig/gtk-sharp/generator/CallbackGen.cs	2002-10-26 19:30:50.000000000 -=
0700
+++ gtk-sharp/generator/CallbackGen.cs	2002-11-03 03:27:31.000000000 -0800
@@ -107,9 +107,6 @@
 				string cstype =3D parms[i].CSType;
 				// FIXME: Too much code copy/pasted here. Refactor?
 				ClassBase parm_wrapper =3D SymbolTable.GetClassGen (ctype);
-				if (parm_wrapper !=3D null && (parm_wrapper is StructBase)) {
-					sw.WriteLine("\t\t\t{0}._Initialize ();", parm_name);
-				}
 				sw.WriteLine("\t\t\t_args[" + idx + "] =3D " + SymbolTable.FromNative =
(ctype, parm_name) + ";");
 				if ((parm_wrapper !=3D null && ((parm_wrapper is OpaqueGen))) || Symbo=
lTable.IsManuallyWrapped (ctype)) {
 					sw.WriteLine("\t\t\tif (_args[" + idx + "] =3D=3D null)");
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/generator/Method.cs gtk-sharp/=
generator/Method.cs
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/generator/SignalHandler.cs gtk=
-sharp/generator/SignalHandler.cs
--- orig/gtk-sharp/generator/SignalHandler.cs	2002-10-26 19:30:50.000000000=
 -0700
+++ gtk-sharp/generator/SignalHandler.cs	2002-11-03 03:28:38.000000000 -080=
0
@@ -143,8 +143,6 @@
 						}
 						sw.WriteLine("\t\t\t}");
 					} else {
-						if (wrapper !=3D null && (wrapper is StructBase))
-							sw.WriteLine("\t\t\targ{0}._Initialize ();", idx);
 						sw.WriteLine("\t\t\targs.Args[" + (idx-1) + "] =3D " + SymbolTable.F=
romNative (ctype, "arg" + idx)  + ";");
 					}
 				}
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/generator/StructBase.cs gtk-sh=
arp/generator/StructBase.cs
--- orig/gtk-sharp/generator/StructBase.cs	2002-10-31 21:01:22.000000000 -0=
800
+++ gtk-sharp/generator/StructBase.cs	2002-11-03 03:30:52.000000000 -0800
@@ -235,25 +235,27 @@
 	=09
 		protected override void GenCtors (StreamWriter sw)
 		{
-			sw.WriteLine ("\t\tbool _is_null;");
-			sw.WriteLine ("\t\tpublic bool IsNull {");
-			sw.WriteLine ("\t\t\tget { return _is_null; }");
-			sw.WriteLine ("\t\t}");
-			sw.WriteLine ("\t\tpublic void _Initialize () {");
-			sw.WriteLine ("\t\t\t_is_null =3D false;");
-			sw.WriteLine ("\t\t}");
+			sw.WriteLine ("\t\tpublic static {0} Zero =3D new {0} ();", QualifiedNa=
me);
 			sw.WriteLine();
 			sw.WriteLine ("\t\tpublic static " + QualifiedName + " New(IntPtr raw) =
{");
-			sw.WriteLine ("\t\t\t{0} self =3D new {0}();", QualifiedName);
 			sw.WriteLine ("\t\t\tif (raw =3D=3D IntPtr.Zero) {");
-			sw.WriteLine ("\t\t\t\tself._is_null =3D true;");
-			sw.WriteLine ("\t\t\t} else {");
-   		sw.WriteLine ("\t\t\t\tself =3D ({0}) Marshal.PtrToStructure (raw, se=
lf.GetType ());", QualifiedName);
-			sw.WriteLine ("\t\t\t\tself._is_null =3D false;");
+			sw.WriteLine ("\t\t\t\treturn {0}.Zero;", QualifiedName);
 			sw.WriteLine ("\t\t\t}");
+			sw.WriteLine ("\t\t\t{0} self =3D new {0}();", QualifiedName);
+			sw.WriteLine ("\t\t\tself =3D ({0}) Marshal.PtrToStructure (raw, self.G=
etType ());", QualifiedName);
 			sw.WriteLine ("\t\t\treturn self;");
 			sw.WriteLine ("\t\t}");
 			sw.WriteLine();
+			sw.WriteLine ("\t\tpublic static bool operator =3D=3D ({0} a, {0} b)", =
QualifiedName);
+			sw.WriteLine ("\t\t{");
+			sw.WriteLine ("\t\t\treturn a.Equals (b);");
+			sw.WriteLine ("\t\t}");
+			sw.WriteLine ();
+			sw.WriteLine ("\t\tpublic static bool operator !=3D ({0} a, {0} b)", Qu=
alifiedName);
+			sw.WriteLine ("\t\t{");
+			sw.WriteLine ("\t\t\treturn ! a.Equals (b);");
+			sw.WriteLine ("\t\t}");
+			sw.WriteLine();
=20
 			foreach (Ctor ctor in Ctors) {
 				ctor.ForceStatic =3D true;
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/glue/Makefile.am gtk-sharp/glu=
e/Makefile.am
--- orig/gtk-sharp/glue/Makefile.am	2002-10-18 22:53:26.000000000 -0700
+++ gtk-sharp/glue/Makefile.am	2002-11-02 07:48:22.000000000 -0800
@@ -16,6 +16,7 @@
 	type.c			\
 	widget.c		\
 	list.c			\
+	clipboard.c		\
 	#
=20
 GNOMESOURCES =3D \
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/glue/clipboard.c gtk-sharp/glu=
e/clipboard.c
--- orig/gtk-sharp/glue/clipboard.c	1969-12-31 16:00:00.000000000 -0800
+++ gtk-sharp/glue/clipboard.c	2002-11-02 07:48:22.000000000 -0800
@@ -0,0 +1,56 @@
+/*
+ * clipboard.c
+ */
+
+#include <gtk/gtk.h>
+
+GSList *
+gtksharp_clipboard_target_list_add (GSList *list, char *target, guint flag=
s, guint info)
+{
+    GtkTargetEntry *entry =3D g_new0 (GtkTargetEntry, 1);
+
+    entry->target =3D g_strdup (target);
+    entry->flags =3D flags;
+    entry->info =3D info;
+
+    return g_slist_prepend (list, entry);
+}
+
+GtkTargetEntry *
+gtksharp_clipboard_target_list_to_array (GSList *list)
+{
+    GtkTargetEntry *targets;
+    GSList *iter;
+    int i;
+
+    targets =3D g_new0 (GtkTargetEntry, g_slist_length (list));
+    for (iter =3D list, i =3D 0; iter; iter =3D iter->next, i++) {
+        GtkTargetEntry *t =3D (GtkTargetEntry *) iter->data;
+        targets[i].target =3D t->target; /* NOT COPIED */
+        targets[i].flags =3D t->flags;
+        targets[i].info =3D t->info;
+    }
+
+    return targets;
+}
+
+void
+gtksharp_clipboard_target_array_free (GtkTargetEntry *targets)
+{
+    g_free (targets);
+}
+
+void
+gtksharp_clipboard_target_list_free (GSList *list)
+{
+    GSList *iter;
+
+    for (iter =3D list; iter; iter =3D iter->next) {
+        GtkTargetEntry *t =3D (GtkTargetEntry *) iter->data;
+        g_free (t->target);
+        g_free (t);
+    }
+
+    g_slist_free (list);
+}
+
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/gnome/voidObjectAffineSVPintSi=
gnal.cs gtk-sharp/gnome/voidObjectAffineSVPintSignal.cs
--- orig/gtk-sharp/gnome/voidObjectAffineSVPintSignal.cs	2002-09-29 19:21:0=
6.000000000 -0700
+++ gtk-sharp/gnome/voidObjectAffineSVPintSignal.cs	2002-11-02 07:48:22.000=
000000 -0800
@@ -27,7 +27,7 @@
 			} else {
 				args.Args[0] =3D null;
 			}
-			arg2._Initialize ();
+
 			args.Args[1] =3D arg2;
 			args.Args[2] =3D arg3;
 		=09
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/gtk/Clipboard.custom gtk-sharp=
/gtk/Clipboard.custom
--- orig/gtk-sharp/gtk/Clipboard.custom	1969-12-31 16:00:00.000000000 -0800
+++ gtk-sharp/gtk/Clipboard.custom	2002-11-02 07:48:22.000000000 -0800
@@ -0,0 +1,54 @@
+
+		public static Hashtable clipboard_objects =3D new Hashtable ();
+		private static uint clipboard_object_next_id =3D 0;
+
+		[DllImport("gtk-x11-2.0")]
+		static extern bool gtk_clipboard_set_with_data(IntPtr raw, IntPtr target=
s, int n_targets, GtkSharp.GtkClipboardGetFuncNative get_func, GtkSharp.Gtk=
ClipboardClearFuncNative clear_func, uint id);
+
+		[DllImport("gtksharpglue")]
+		static extern IntPtr gtksharp_clipboard_target_list_add (IntPtr list, st=
ring name, uint flags, uint info);
+
+		[DllImport("gtksharpglue")]
+		static extern IntPtr gtksharp_clipboard_target_list_to_array (IntPtr lis=
t);
+
+		[DllImport("gtksharpglue")]
+		static extern void gtksharp_clipboard_target_array_free (IntPtr targets)=
;
+
+		[DllImport("gtksharpglue")]
+		static extern void gtksharp_clipboard_target_list_free (IntPtr list);
+
+		GtkSharp.GtkClipboardGetFuncWrapper get_func_wrapper;
+		GtkSharp.GtkClipboardClearFuncWrapper clear_func_wrapper;
+
+		public bool Set (Gtk.TargetEntry[] targets,
+				 Gtk.ClipboardGetFunc get_func,
+				 Gtk.ClipboardClearFunc clear_func,
+				 object data)
+		{
+			uint this_id;
+
+			lock (clipboard_objects) {
+				this_id =3D clipboard_object_next_id++;
+				clipboard_objects[this_id] =3D data;
+			}
+
+			get_func_wrapper =3D new GtkSharp.GtkClipboardGetFuncWrapper (get_func)=
;
+			clear_func_wrapper =3D new GtkSharp.GtkClipboardClearFuncWrapper (clear=
_func);
+
+			IntPtr list =3D IntPtr.Zero;
+
+			foreach (Gtk.TargetEntry t in targets) {
+				list =3D gtksharp_clipboard_target_list_add (list, t.target, t.flags, =
t.info);
+			}
+
+			IntPtr array =3D gtksharp_clipboard_target_list_to_array (list);
+
+			bool ret =3D gtk_clipboard_set_with_data (Handle, array, targets.Length=
, get_func_wrapper.NativeDelegate, clear_func_wrapper.NativeDelegate, this_=
id);
+
+			gtksharp_clipboard_target_array_free (array);
+			gtksharp_clipboard_target_list_free (list);
+
+			return ret;
+		}
+
+
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/gtk/ClipboardClearFunc.cs gtk-=
sharp/gtk/ClipboardClearFunc.cs
--- orig/gtk-sharp/gtk/ClipboardClearFunc.cs	1969-12-31 16:00:00.000000000 =
-0800
+++ gtk-sharp/gtk/ClipboardClearFunc.cs	2002-11-02 07:48:22.000000000 -0800
@@ -0,0 +1,8 @@
+// Generated File.  Do not modify.
+// <c> 2001-2002 Mike Kestner
+
+namespace Gtk {
+
+	public delegate void ClipboardClearFunc(Gtk.Clipboard clipboard, object o=
);
+
+}
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/gtk/ClipboardGetFunc.cs gtk-sh=
arp/gtk/ClipboardGetFunc.cs
--- orig/gtk-sharp/gtk/ClipboardGetFunc.cs	1969-12-31 16:00:00.000000000 -0=
800
+++ gtk-sharp/gtk/ClipboardGetFunc.cs	2002-11-02 07:48:22.000000000 -0800
@@ -0,0 +1,8 @@
+// Generated File.  Do not modify.
+// <c> 2001-2002 Mike Kestner
+
+namespace Gtk {
+
+	public delegate void ClipboardGetFunc(Gtk.Clipboard clipboard, ref Gtk.Se=
lectionData selection_data, uint info, object o);
+
+}
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/gtk/GtkSharp.GtkClipboardClear=
FuncNative.cs gtk-sharp/gtk/GtkSharp.GtkClipboardClearFuncNative.cs
--- orig/gtk-sharp/gtk/GtkSharp.GtkClipboardClearFuncNative.cs	1969-12-31 1=
6:00:00.000000000 -0800
+++ gtk-sharp/gtk/GtkSharp.GtkClipboardClearFuncNative.cs	2002-11-02 07:48:=
22.000000000 -0800
@@ -0,0 +1,31 @@
+
+namespace GtkSharp {
+
+	using System;
+	using System.Collections;
+	public delegate void GtkClipboardClearFuncNative(IntPtr clipboard, uint o=
bjid);
+
+	public class GtkClipboardClearFuncWrapper : GLib.DelegateWrapper {
+
+		public void NativeCallback (IntPtr clipboard, uint objid)
+		{
+			object[] _args =3D new object[2];
+			_args[0] =3D (Gtk.Clipboard) GLib.Opaque.GetOpaque(clipboard);
+			if (_args[0] =3D=3D null)
+				_args[0] =3D new Gtk.Clipboard(clipboard);
+                        _args[1] =3D Gtk.Clipboard.clipboard_objects[objid=
];
+			_managed ((Gtk.Clipboard) _args[0], _args[1]);
+                        Gtk.Clipboard.clipboard_objects.Remove (objid);
+		}
+
+		public GtkClipboardClearFuncNative NativeDelegate;
+		protected Gtk.ClipboardClearFunc _managed;
+
+		public GtkClipboardClearFuncWrapper (Gtk.ClipboardClearFunc managed) : b=
ase ()
+		{
+			NativeDelegate =3D new GtkClipboardClearFuncNative (NativeCallback);
+			_managed =3D managed;
+		}
+	}
+
+}
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/gtk/GtkSharp.GtkClipboardGetFu=
ncNative.cs gtk-sharp/gtk/GtkSharp.GtkClipboardGetFuncNative.cs
--- orig/gtk-sharp/gtk/GtkSharp.GtkClipboardGetFuncNative.cs	1969-12-31 16:=
00:00.000000000 -0800
+++ gtk-sharp/gtk/GtkSharp.GtkClipboardGetFuncNative.cs	2002-11-02 07:48:22=
.000000000 -0800
@@ -0,0 +1,33 @@
+
+namespace GtkSharp {
+
+	using System;
+	using System.Collections;
+	public delegate void GtkClipboardGetFuncNative(IntPtr clipboard, ref Gtk.=
SelectionData selection_data, uint info, uint obj_id);
+
+	public class GtkClipboardGetFuncWrapper : GLib.DelegateWrapper {
+
+		public void NativeCallback (IntPtr clipboard, ref Gtk.SelectionData sele=
ction_data, uint info, uint obj_id)
+		{
+			object[] _args =3D new object[4];
+			_args[0] =3D (Gtk.Clipboard) GLib.Opaque.GetOpaque(clipboard);
+			if (_args[0] =3D=3D null)
+				_args[0] =3D new Gtk.Clipboard(clipboard);
+			_args[1] =3D selection_data;
+			_args[2] =3D info;
+                        _args[3] =3D Gtk.Clipboard.clipboard_objects[obj_i=
d];
+
+			_managed ((Gtk.Clipboard) _args[0], ref selection_data, (uint) _args[2]=
, _args[3]);
+		}
+
+		public GtkClipboardGetFuncNative NativeDelegate;
+		protected Gtk.ClipboardGetFunc _managed;
+
+		public GtkClipboardGetFuncWrapper (Gtk.ClipboardGetFunc managed) : base =
()
+		{
+			NativeDelegate =3D new GtkClipboardGetFuncNative (NativeCallback);
+			_managed =3D managed;
+		}
+	}
+
+}
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/gtk/SelectionData.custom gtk-s=
harp/gtk/SelectionData.custom
--- orig/gtk-sharp/gtk/SelectionData.custom	1969-12-31 16:00:00.000000000 -=
0800
+++ gtk-sharp/gtk/SelectionData.custom	2002-11-02 07:48:22.000000000 -0800
@@ -0,0 +1,29 @@
+
+		[DllImport("gtk-x11-2.0")]
+		private static extern string gtk_selection_data_get_text (ref Gtk.Select=
ionData selection_data);
+
+		[DllImport("gtk-x11-2.0")]
+		private static extern void gtk_selection_data_set_text (ref Gtk.Selectio=
nData selection_data, string str, int len);
+
+		public string Text {
+			get {
+				return gtk_selection_data_get_text (ref this);
+			}
+			set {
+				gtk_selection_data_set_text (ref this, value, value.Length);
+			}
+		}
+
+		[DllImport("gtk-x11-2.0")]
+		static extern void gtk_selection_data_set (ref Gtk.SelectionData raw, In=
tPtr type, int format, byte[] data, int length);
+
+		public byte[] Data {
+			get {
+				byte[] ret =3D new byte[length];
+				Marshal.Copy (_data, ret, 0, length);
+				return ret;
+			}
+			set {
+				gtk_selection_data_set (ref this, _type, format, value, value.Length);
+			}
+		}
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/sources/Gtk.metadata gtk-sharp=
/sources/Gtk.metadata
--- orig/gtk-sharp/sources/Gtk.metadata	2002-10-08 12:14:14.000000000 -0700
+++ gtk-sharp/sources/Gtk.metadata	2002-11-02 07:48:22.000000000 -0800
@@ -1286,6 +1286,19 @@
     </attribute>
   </data>
 </rule>
+<rule>
+  <class name=3D"GtkSelectionData">
+    <method>GetText</method>
+    <method>SetText</method>
+    <method>Set</method>
+  </class>
+  <data>
+    <attribute target=3D"method">
+      <name>hidden</name>
+      <value>1</value>
+    </attribute>
+  </data>
+</rule>
=20
 <!-- overloads -->
 <rule>
@@ -1854,7 +1867,7 @@
=20
 <!-- reference rules -->
 <rule>
-  <class name=3D"GtkWidget">
+<!--  <class name=3D"GtkWidget">
     <method>GetStyle</method>
     <method>GetModifierStyle</method>
     <method>GetDefaultStyle</method>
@@ -1870,6 +1883,7 @@
       <value>1</value>
     </attribute>
   </data>
+-->
=20
 </rule>
=20
diff -Nuw -r -x CVS -x '*.m4' orig/gtk-sharp/api/gtk-api.xml gtk-sharp/api/=
gtk-api.xml
--- orig/gtk-sharp/api/gtk-api.xml	2002-10-08 12:32:29.000000000 -0700
+++ gtk-sharp/api/gtk-api.xml	2002-11-02 07:48:22.000000000 -0800
@@ -506,22 +506,6 @@
         <parameter type=3D"GtkArg*" name=3D"args"/>
       </parameters>
     </callback>
-    <callback name=3D"ClipboardClearFunc" cname=3D"GtkClipboardClearFunc">
-      <return-type type=3D"void"/>
-      <parameters>
-        <parameter type=3D"GtkClipboard*" name=3D"clipboard"/>
-        <parameter type=3D"gpointer" name=3D"user_data_or_owner"/>
-      </parameters>
-    </callback>
-    <callback name=3D"ClipboardGetFunc" cname=3D"GtkClipboardGetFunc">
-      <return-type type=3D"void"/>
-      <parameters>
-        <parameter type=3D"GtkClipboard*" name=3D"clipboard"/>
-        <parameter type=3D"GtkSelectionData*" name=3D"selection_data"/>
-        <parameter type=3D"guint" name=3D"info"/>
-        <parameter type=3D"gpointer" name=3D"user_data_or_owner"/>
-      </parameters>
-    </callback>
     <callback name=3D"ClipboardReceivedFunc" cname=3D"GtkClipboardReceived=
Func">
       <return-type type=3D"void"/>
       <parameters>
@@ -10487,26 +10471,6 @@
           <parameter type=3D"gint" name=3D"len"/>
         </parameters>
       </method>
-      <method name=3D"SetWithData" cname=3D"gtk_clipboard_set_with_data">
-        <return-type type=3D"gboolean"/>
-        <parameters>
-          <parameter type=3D"const-GtkTargetEntry*" name=3D"targets"/>
-          <parameter type=3D"guint" name=3D"n_targets"/>
-          <parameter type=3D"GtkClipboardGetFunc" name=3D"get_func"/>
-          <parameter type=3D"GtkClipboardClearFunc" name=3D"clear_func"/>
-          <parameter type=3D"gpointer" name=3D"user_data"/>
-        </parameters>
-      </method>
-      <method name=3D"SetWithOwner" cname=3D"gtk_clipboard_set_with_owner"=
>
-        <return-type type=3D"gboolean"/>
-        <parameters>
-          <parameter type=3D"const-GtkTargetEntry*" name=3D"targets"/>
-          <parameter type=3D"guint" name=3D"n_targets"/>
-          <parameter type=3D"GtkClipboardGetFunc" name=3D"get_func"/>
-          <parameter type=3D"GtkClipboardClearFunc" name=3D"clear_func"/>
-          <parameter type=3D"GObject*" name=3D"owner"/>
-        </parameters>
-      </method>
       <method name=3D"WaitForContents" cname=3D"gtk_clipboard_wait_for_con=
tents">
         <return-type type=3D"GtkSelectionData*"/>
         <parameters>
@@ -10809,28 +10773,9 @@
           <parameter type=3D"gint*" name=3D"n_atoms"/>
         </parameters>
       </method>
-      <method name=3D"GetText" cname=3D"gtk_selection_data_get_text">
-        <return-type type=3D"guchar*"/>
-      </method>
       <method name=3D"GetType" cname=3D"gtk_selection_data_get_type" share=
d=3D"true">
         <return-type type=3D"GType"/>
       </method>
-      <method name=3D"Set" cname=3D"gtk_selection_data_set">
-        <return-type type=3D"void"/>
-        <parameters>
-          <parameter type=3D"GdkAtom" name=3D"type"/>
-          <parameter type=3D"gint" name=3D"format"/>
-          <parameter type=3D"const-guchar*" name=3D"data"/>
-          <parameter type=3D"gint" name=3D"length"/>
-        </parameters>
-      </method>
-      <method name=3D"SetText" cname=3D"gtk_selection_data_set_text">
-        <return-type type=3D"gboolean"/>
-        <parameters>
-          <parameter type=3D"const-gchar*" name=3D"str"/>
-          <parameter type=3D"gint" name=3D"len"/>
-        </parameters>
-      </method>
       <method name=3D"TargetsIncludeText" cname=3D"gtk_selection_data_targ=
ets_include_text">
         <return-type type=3D"gboolean"/>
       </method>

--=-d6IWdtLLuS8DypcXo63E--