[Gtk-sharp-list] PATCH: TextIter usage

Rachel Hestilow hestilow@ximian.com
09 Jun 2002 03:54:28 -0500


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

I've been playing with the idea of an interactive LOGO console using
Gtk#, and I ran into problems with the text widget - namely, "out"
parameters (as TextIter is often used) are not supported. Additionally,
code needed to be added to allocate TextIter on the heap, not the stack
as is usually the case with GtkTextIter. The attached patch makes the
following changes:

* Add support for metadata in the xml generator. Additional properties
  for given methods will be loaded from <namespace>.metadata.
  This exposed a bug in LibXML. It has been fixed in CVS, so you will
  need to use that if you want to regenerate gtkapi.xml.
* Add a textiter constructor to the glue library.
* Check for .custom files for all generatable targets, and include
  a TextIter.custom that calls the glue constructor.
* Check for a new parameter attribute, "pass_as", to indicate if
  the parameter should be passed as "out." As an additional niceity,
  if the method is named Get* and has only the one out parameter, 
  generate an accessor instead of the method.

With these changes, an application author can simply call
         buf.Insert (buf.EndIter, txt, txt.Length);
to append text to a buffer.

May I commit this and the regenerated gtkapi.xml?

-- Rachel

--=-aVpYgBEomaDJ/XfCSZTc
Content-Disposition: inline; filename=textiter.patch
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=textiter.patch; charset=ISO-8859-1

Index: ChangeLog
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/ChangeLog,v
retrieving revision 1.94
diff -u -r1.94 ChangeLog
--- ChangeLog	6 Jun 2002 23:17:10 -0000	1.94
+++ ChangeLog	9 Jun 2002 04:56:33 -0000
@@ -1,3 +1,21 @@
+2002-06-09  Rachel Hestilow  <hestilow@ximian.com>
+
+	* generator/GenBase.cs: new method AppendCustom, moved from ObjectGen.
+	* generator/BoxedGen.cs, EnumGen.cs, ObjectGen.cs, StructGen.cs:
+	Call AppendCustom in Generate ();
+	* generator/Method.cs, Parameters.cs: Add support for "out"
+	parameters. Additionally, output an accessor instead of a
+	regular method if it is an accessor-style function (ie GetStartIter).
+	* generator/Property.cs: Add additional cast to Boxed, if necessary.
+	* glue/textiter.c: New constructor for GtkTextIter.
+	* glue/Makefile.am: Add textiter.c, build with Gtk+ cflags.
+	* configure.in: Check for Gtk+ cflags.
+	* parser/Metadata.pm, Gtk.metadata: Added.
+	* parser/gapi2xml.pl: Call Metadata::fixup on the document.
+	Also work around gtk's screwy boxed type name registration
+	(GtkFoo -> GtkTypeFoo).
+	* gtk/TextIter.custom: Added.
+=09
 2002-06-06  Mike Kestner <mkestner@speakeasy.net>
=20
 	* glib/Timeout.cs : new Timeout class with Add() and=20
Index: configure.in
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/configure.in,v
retrieving revision 1.2
diff -u -r1.2 configure.in
--- configure.in	2 May 2002 21:57:40 -0000	1.2
+++ configure.in	9 Jun 2002 04:56:33 -0000
@@ -39,10 +39,10 @@
=20
 dnl for use on the build system
 dnl pkg-config is stupid
-BUILD_GLIB_CFLAGS=3D`$PKG_CONFIG --cflags glib-2.0`
-BUILD_GLIB_LIBS=3D`$PKG_CONFIG --libs glib-2.0`
-AC_SUBST(BUILD_GLIB_CFLAGS)
-AC_SUBST(BUILD_GLIB_LIBS)
+BUILD_GTK_CFLAGS=3D`$PKG_CONFIG --cflags gtk+-2.0`
+BUILD_GTK_LIBS=3D`$PKG_CONFIG --libs gtk+-2.0`
+AC_SUBST(BUILD_GTK_CFLAGS)
+AC_SUBST(BUILD_GTK_LIBS)
=20
 PKG_PATH=3D
 AC_ARG_WITH(crosspkgdir, [  --with-crosspkgdir=3D/path/to/pkg-config/dir],
@@ -58,17 +58,17 @@
 )
=20
 ## Versions of dependencies
-GLIB_REQUIRED_VERSION=3D2.0.0
+GTK_REQUIRED_VERSION=3D2.0.0
=20
-PKG_CHECK_MODULES(BASE_DEPENDENCIES, glib-2.0 >=3D $GLIB_REQUIRED_VERSION)
+PKG_CHECK_MODULES(BASE_DEPENDENCIES, gtk+-2.0 >=3D $GTK_REQUIRED_VERSION)
=20
-GLIB_CFLAGS=3D`$PKG_CONFIG --cflags glib-2.0`
-GLIB_LIBS=3D`$PKG_CONFIG --libs glib-2.0`
+GTK_CFLAGS=3D`$PKG_CONFIG --cflags gtk+-2.0`
+GTK_LIBS=3D`$PKG_CONFIG --libs gtk+-2.0`
 GMODULE_CFLAGS=3D`$PKG_CONFIG --cflags gmodule-2.0`
 GMODULE_LIBS=3D`$PKG_CONFIG --libs gmodule-2.0`
=20
-AC_SUBST(GLIB_CFLAGS)
-AC_SUBST(GLIB_LIBS)
+AC_SUBST(GTK_CFLAGS)
+AC_SUBST(GTK_LIBS)
 AC_SUBST(GMODULE_CFLAGS)
 AC_SUBST(GMODULE_LIBS)
=20
Index: generator/BoxedGen.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/generator/BoxedGen.cs,v
retrieving revision 1.10
diff -u -r1.10 BoxedGen.cs
--- generator/BoxedGen.cs	23 May 2002 23:43:24 -0000	1.10
+++ generator/BoxedGen.cs	9 Jun 2002 04:56:33 -0000
@@ -97,6 +97,7 @@
 				}	=09=0D
 			}=0D
 		=09=0D
+			GenBase.AppendCustom(ns, Name, sw);=0D
 			sw.WriteLine ("\t}");=0D
 			sw.WriteLine ();=0D
 			sw.WriteLine ("}");=0D
Index: generator/EnumGen.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/generator/EnumGen.cs,v
retrieving revision 1.9
diff -u -r1.9 EnumGen.cs
--- generator/EnumGen.cs	23 May 2002 23:43:24 -0000	1.9
+++ generator/EnumGen.cs	9 Jun 2002 04:56:33 -0000
@@ -33,6 +33,8 @@
 	=09=0D
 		public void Generate ()=0D
 		{=0D
+			if (Name.IndexOf (',') !=3D -1)=0D
+				return;=0D
 			StreamWriter sw =3D CreateWriter ();=0D
=20=0D
 			if (Elem.GetAttribute("type") =3D=3D "flags") {=0D
Index: generator/GenBase.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/generator/GenBase.cs,v
retrieving revision 1.1
diff -u -r1.1 GenBase.cs
--- generator/GenBase.cs	23 May 2002 23:43:24 -0000	1.1
+++ generator/GenBase.cs	9 Jun 2002 04:56:33 -0000
@@ -59,6 +59,7 @@
 				Directory.CreateDirectory(dir);=0D
 			}=0D
 			String filename =3D dir + sep + Name + ".cs";=0D
+			Console.WriteLine ("creating " + filename);=0D
 		=09=0D
 			FileStream stream =3D new FileStream (filename, FileMode.Create, FileAc=
cess.Write);=0D
 			StreamWriter sw =3D new StreamWriter (stream);=0D
@@ -80,6 +81,17 @@
 			sw.Close();=0D
 		}=0D
 	=09=0D
+		public static void AppendCustom (string ns, string name, StreamWriter sw=
)=0D
+		{=0D
+			char sep =3D Path.DirectorySeparatorChar;=0D
+			string custom =3D ".." + sep + ns.ToLower() + sep + name + ".custom";=0D
+			if (File.Exists(custom)) {=0D
+				FileStream custstream =3D new FileStream(custom, FileMode.Open, FileAc=
cess.Read);=0D
+				StreamReader sr =3D new StreamReader(custstream);=0D
+				sw.WriteLine (sr.ReadToEnd ());=0D
+				sr.Close ();=0D
+			}=0D
+		}=0D
 	}=0D
 }=0D
=20=0D
Index: generator/Method.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/generator/Method.cs,v
retrieving revision 1.1
diff -u -r1.1 Method.cs
--- generator/Method.cs	23 May 2002 23:43:24 -0000	1.1
+++ generator/Method.cs	9 Jun 2002 04:56:33 -0000
@@ -103,7 +103,7 @@
 		public void Generate (StreamWriter sw)=0D
 		{=0D
 			string sig, isig, call;=0D
-=0D
+		=09=0D
 			if (parms !=3D null) {=0D
 				sig =3D "(" + parms.Signature + ")";=0D
 				isig =3D "(IntPtr raw, " + parms.ImportSig + ");";=0D
@@ -130,18 +130,37 @@
 			sw.WriteLine();=0D
=20=0D
 			sw.Write("\t\tpublic ");=0D
-			if (elem.HasAttribute("new_flag"))=0D
-				sw.Write("new ");=0D
-			sw.WriteLine(s_ret + " " + Name + sig);=0D
+			bool is_get =3D (parms !=3D null && parms.IsAccessor && Name.Substring(=
0, 3) =3D=3D "Get");=0D
+			if (is_get) {=0D
+				s_ret =3D parms.AccessorReturnType;=0D
+				sw.Write(s_ret);=0D
+				sw.Write(" ");=0D
+				sw.Write(Name.Substring (3));=0D
+				sw.Write(" { get");=0D
+			} else {=0D
+				if (elem.HasAttribute("new_flag"))=0D
+					sw.Write("new ");=0D
+				sw.WriteLine(s_ret + " " + Name + sig);=0D
+			}=0D
 			sw.WriteLine("\t\t{");=0D
+			if (parms !=3D null)=0D
+				parms.Initialize(sw, is_get);=0D
 			sw.Write("\t\t\t");=0D
-			if (m_ret =3D=3D "void") {=0D
+			if (is_get || m_ret =3D=3D "void") {=0D
 				sw.WriteLine(cname + call + ";");=0D
 			} else {=0D
 				sw.WriteLine("return " + SymbolTable.FromNative(rettype, cname + call)=
 + ";");=0D
 			}=0D
+		=09=0D
+			if (is_get)=20=0D
+				sw.WriteLine ("\t\t\treturn " + parms.AccessorName + ";");=20=0D
=20=0D
-			sw.WriteLine("\t\t}");=0D
+=0D
+			sw.Write("\t\t}");=0D
+			if (is_get)=0D
+				sw.Write(" }");=0D
+		=09=0D
+			sw.WriteLine();=0D
 			sw.WriteLine();=0D
=20=0D
 			Statistics.MethodCount++;=0D
Index: generator/ObjectGen.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/generator/ObjectGen.cs,v
retrieving revision 1.22
diff -u -r1.22 ObjectGen.cs
--- generator/ObjectGen.cs	23 May 2002 23:43:24 -0000	1.22
+++ generator/ObjectGen.cs	9 Jun 2002 04:56:33 -0000
@@ -96,15 +96,7 @@
 			GenProperties (sw);=0D
 			GenSignals (sw);=0D
 			GenMethods (sw);=0D
-=0D
-			char sep =3D Path.DirectorySeparatorChar;=0D
-			string custom =3D ".." + sep + Namespace.ToLower() + sep + Name + ".cus=
tom";=0D
-			if (File.Exists(custom)) {=0D
-				FileStream custstream =3D new FileStream (custom, FileMode.Open, FileA=
ccess.Read);=0D
-				StreamReader sr =3D new StreamReader (custstream);=0D
-				sw.WriteLine (sr.ReadToEnd ());=0D
-				sr.Close ();=0D
-			}=0D
+			AppendCustom(Namespace, Name, sw);=0D
=20=0D
 			sw.WriteLine ("\t}");=0D
=20=0D
Index: generator/Parameters.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/generator/Parameters.cs,v
retrieving revision 1.1
diff -u -r1.1 Parameters.cs
--- generator/Parameters.cs	23 May 2002 23:43:24 -0000	1.1
+++ generator/Parameters.cs	9 Jun 2002 04:56:33 -0000
@@ -7,6 +7,7 @@
 namespace GtkSharp.Generation {=0D
=20=0D
 	using System;=0D
+	using System.IO;=0D
 	using System.Xml;=0D
=20=0D
 	public class Parameters  {=0D
@@ -83,6 +84,10 @@
 					need_sep =3D true;=0D
 				}=0D
=20=0D
+				if (p_elem.HasAttribute("pass_as")) {=0D
+					signature +=3D p_elem.GetAttribute("pass_as") + " ";=0D
+				}=0D
+=0D
 				signature +=3D (cs_type + " " + name);=0D
 				signature_types +=3D cs_type;=0D
 				call_string +=3D call_parm;=0D
@@ -91,7 +96,74 @@
 		=09=0D
 			return true;=0D
 		}=0D
-	=09=0D
+=0D
+		public void Initialize (StreamWriter sw, bool is_get)=0D
+		{=0D
+			foreach (XmlNode parm in elem.ChildNodes) {=0D
+				if (parm.Name !=3D "parameter") {=0D
+					continue;=0D
+				}=0D
+=0D
+				XmlElement p_elem =3D (XmlElement) parm;=0D
+=0D
+				string type =3D SymbolTable.GetCSType(p_elem.GetAttribute ("type"));=0D
+				string name =3D MangleName(p_elem.GetAttribute("name"));=0D
+				if (is_get) {=0D
+					sw.WriteLine ("\t\t\t" + type + " " + name + ";");=0D
+				}=0D
+=0D
+				if (is_get || (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute (=
"pass_as") =3D=3D "out")) {=0D
+					sw.WriteLine("\t\t\t" + name + " =3D new " + type + "();");=20=0D
+				}=0D
+			}=0D
+		=09=0D
+		}=0D
+=0D
+		public bool IsAccessor {=0D
+			get {=0D
+				int length =3D 0;=0D
+				string pass_as;=0D
+				foreach (XmlNode parm in elem.ChildNodes) {=0D
+					if (parm.Name !=3D "parameter") {=0D
+						continue;=0D
+					}=0D
+=09=0D
+					XmlElement p_elem =3D (XmlElement) parm;=0D
+					length++;=0D
+					if (length > 1)=0D
+						return false;=0D
+					if (p_elem.HasAttribute("pass_as"))=0D
+						pass_as =3D p_elem.GetAttribute("pass_as");=0D
+				}=0D
+=0D
+				return (length =3D=3D 1 && pass_as =3D=3D "out");=0D
+			}=0D
+		}=0D
+=0D
+		public string AccessorReturnType {=0D
+			get {=0D
+				foreach (XmlNode parm in elem.ChildNodes) {=0D
+					if (parm.Name !=3D "parameter")=20=0D
+						continue;=0D
+					XmlElement p_elem =3D (XmlElement) parm;=0D
+					return SymbolTable.GetCSType(p_elem.GetAttribute ("type"));=0D
+				}=0D
+				return null;=0D
+			}=0D
+		}=0D
+=0D
+		public string AccessorName {=0D
+			get {=0D
+				foreach (XmlNode parm in elem.ChildNodes) {=0D
+					if (parm.Name !=3D "parameter")=20=0D
+						continue;=0D
+					XmlElement p_elem =3D (XmlElement) parm;=0D
+					return MangleName (p_elem.GetAttribute("name"));=0D
+				}=0D
+				return null;=0D
+			}=0D
+		}=0D
+=0D
 		private string MangleName(string name)=0D
 		{=0D
 			switch (name) {=0D
Index: generator/Property.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/generator/Property.cs,v
retrieving revision 1.2
diff -u -r1.2 Property.cs
--- generator/Property.cs	5 Jun 2002 21:59:10 -0000	1.2
+++ generator/Property.cs	9 Jun 2002 04:56:33 -0000
@@ -63,6 +63,8 @@
 				return;=0D
 			} else if (SymbolTable.IsObject(c_type)) {=0D
 				v_type =3D "GLib.Object";=0D
+			} else if (SymbolTable.IsBoxed (c_type)) {=0D
+				v_type =3D "GLib.Boxed";=0D
 			}=0D
=20=0D
 			if (elem.HasAttribute("construct-only") && !elem.HasAttribute("readable=
")) {=0D
Index: generator/StructGen.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/generator/StructGen.cs,v
retrieving revision 1.10
diff -u -r1.10 StructGen.cs
--- generator/StructGen.cs	23 May 2002 23:43:25 -0000	1.10
+++ generator/StructGen.cs	9 Jun 2002 04:56:33 -0000
@@ -87,6 +87,8 @@
 				}	=09=0D
 			}=0D
 		=09=0D
+			GenBase.AppendCustom(ns, Name, sw);=0D
+		=09=0D
 			sw.WriteLine ("\t}");=0D
 			sw.WriteLine ();=0D
 			sw.WriteLine ("}");=0D
Index: glue/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/glue/Makefile.am,v
retrieving revision 1.1
diff -u -r1.1 Makefile.am
--- glue/Makefile.am	25 Apr 2002 09:17:54 -0000	1.1
+++ glue/Makefile.am	9 Jun 2002 04:56:33 -0000
@@ -1,9 +1,10 @@
 lib_LTLIBRARIES =3D libgtksharpglue.la
=20
-INCLUDES =3D $(GLIB_CFLAGS) -I$(top_srcdir)
+INCLUDES =3D $(GTK_CFLAGS) -I$(top_srcdir)
=20
 libgtksharpglue_la_SOURCES =3D 	\
 	value.c			\
+	textiter.c		\
 	#
=20
 libgtksharpglue.dll: $(libgtksharpglue_la_OBJECTS) libgtksharpglue.rc libg=
tksharpglue.def
Index: glue/textiter.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: glue/textiter.c
diff -N glue/textiter.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ glue/textiter.c	9 Jun 2002 04:56:33 -0000
@@ -0,0 +1,17 @@
+/* textiter.c : Glue to allocate GtkTextIters on the heap.
+ *
+ * Author: Rachel Hestilow  <hestilow@ximian.com>
+ *
+ * <c> 2002 Rachel Hestilow, Mike Kestner
+ */
+
+#include <gtk/gtktextiter.h>
+
+GtkTextIter*
+gtksharp_text_iter_create (void)
+{
+	GtkTextIter *iter =3D g_new0 (GtkTextIter, 1);
+	return iter;
+}
+
+
Index: gtk/TextIter.custom
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: gtk/TextIter.custom
diff -N gtk/TextIter.custom
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gtk/TextIter.custom	9 Jun 2002 04:56:33 -0000
@@ -0,0 +1,30 @@
+// Gtk.TextIter.custom - Gtk TextIter class customizations
+//
+// Author: Rachel Hestilow <hestilow@ximian.com>=20
+//
+// (c) 2001 Mike Kestner, 2002 Rachel Hestilow
+//
+// This code is inserted after the automatically generated code.
+
+
+		/// <summary>
+		///	TextIter Constructor
+		/// </summary>
+		///=20
+		/// <remarks>
+		///	Constructs a new TextIter.
+
+		[DllImport("gtksharpglue")]
+		static extern IntPtr gtksharp_text_iter_create();
+		public TextIter () : this (gtksharp_text_iter_create ())=20
+		{
+		}
+	=09
+		[DllImport("glib-2.0")]
+		static extern void g_free (IntPtr mem);
+
+		~TextIter ()
+		{
+			g_free (Handle);
+		}
+
Index: parser/Gtk.metadata
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: parser/Gtk.metadata
diff -N parser/Gtk.metadata
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ parser/Gtk.metadata	9 Jun 2002 04:56:33 -0000
@@ -0,0 +1,31 @@
+<?xml version=3D"1.0"?>
+<metadata>
+<rule>
+  <class name=3D"GtkTextBuffer">
+    <method>GetIterAtLineOffset</method>
+    <method>GetIterAtLineIndex</method>
+    <method>GetIterAtOffset</method>
+    <method>GetIterAtLine</method>
+    <method>GetStartIter</method>
+    <method>GetEndIter</method>
+    <method>GetBounds</method>
+    <method>GetIterAtMark</method>
+    <method>GetIterAtChildAnchor</method>
+    <method>GetSelectionBounds</method>
+  </class>
+  <class name=3D"GtkTextLayout">
+    <method>GetIterAtLine</method>
+  </class>
+  <class name=3D"GtkTextView">
+    <method>GetIterAtLocation</method>
+    <method>GetLineAtY</method>
+  </class>
+  <data>
+    <attribute target=3D"param">
+      <filter level=3D"type">GtkTextIter*</filter>
+      <name>pass_as</name>
+      <value>out</value>
+    </attribute>
+  </data>
+</rule>
+</metadata>
Index: parser/Metadata.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: parser/Metadata.pm
diff -N parser/Metadata.pm
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ parser/Metadata.pm	9 Jun 2002 04:56:33 -0000
@@ -0,0 +1,190 @@
+#
+# Metadata.pm: Adds additional properties to a GApi tree.=20
+#
+# Author: Rachel Hestilow  <hestilow@ximian.com>=20
+#
+# <c> 2002 Rachel Hestilow
+##############################################################
+
+package Metadata;
+
+use XML::LibXML;
+
+sub new {
+	my $namespace =3D $_[1];
+	my $file =3D "$namespace.metadata";
+	my $self =3D {};
+	@{$self->{rules}} =3D ();
+	$self->{metadata} =3D $namespace;
+	bless $self;
+	$self->load ($file);
+	return $self;
+}
+
+sub parseClass {
+	my ($node, $classes) =3D @_;
+	my %methods =3D ();
+	my @attrs =3D $node->attributes;
+	my $class_name =3D $attrs[0]->value;
+	${$classes}{$class_name} =3D \%methods;
+
+	for ($method_node =3D $node->firstChild; $method_node !=3D undef; $method=
_node =3D $method_node->nextSibling ()) {
+		next if $method_node->nodeName ne "method";
+		$methods{$method_node->firstChild->nodeValue} =3D 1;
+	}
+}
+
+sub parseData {
+	my $node =3D $_[0];
+	my @data =3D ();
+	for ($data_node =3D $node->firstChild; $data_node !=3D undef; $data_node =
=3D $data_node->nextSibling ()) {
+		next if $data_node->nodeName ne "attribute";
+		my @attrs =3D $data_node->attributes;
+		my $target =3D $attrs[0]->value;
+		my ($filter_level, $filter_value, $attr_name, $attr_value);
+		for ($attr_node =3D $data_node->firstChild; $attr_node !=3D undef; $attr=
_node =3D $attr_node->nextSibling ()) {
+			if ($attr_node->nodeName eq "filter") {
+				my @filter_attrs =3D $attr_node->attributes;
+				$filter_level =3D $filter_attrs[0]->value;
+				$filter_value =3D $attr_node->firstChild->nodeValue;
+			} elsif ($attr_node->nodeName eq "name") {
+				$attr_name =3D $attr_node->firstChild->nodeValue;
+			} elsif ($attr_node->nodeName eq "value") {
+				$attr_value =3D $attr_node->firstChild->nodeValue;
+			}
+		}
+		my @data_attr =3D ("attribute", $target, "filter", $filter_level, $filte=
r_value, $attr_name, $attr_value);
+		push @data, \@data_attr;
+	}
+
+	return @data;
+}
+			=09
+sub load {
+	my ($self, $file) =3D @_;
+	my $parser =3D new XML::LibXML;
+	my $doc =3D $parser->parse_file($file);
+	my $root =3D $doc->documentElement;
+	for ($rule_node =3D $root->firstChild; $rule_node !=3D undef; $rule_node =
=3D $rule_node->nextSibling ()) {
+		next if $rule_node->nodeName ne "rule";
+		my %classes =3D ();
+		my @data;
+		for ($node =3D $rule_node->firstChild; $node !=3D undef; $node =3D $node=
->nextSibling ()) {
+			if ($node->nodeName eq "class") {
+				parseClass ($node, \%classes);
+			} elsif ($node->nodeName eq "data") {
+				@data =3D parseData ($node);=09
+			}
+		}
+		=09
+		push @{$self->{rules}}, [\%classes, \@data];
+	}
+}
+
+sub fixupParams {
+	my ($method_node, $data_list_ref) =3D @_;
+	my ($params_node, $node);
+	for ($node =3D $method_node->firstChild; $node; $node =3D $node->nextSibl=
ing ()) {
+		if ($node->nodeName eq "parameters") {
+			$params_node =3D $node;
+			last;
+		}
+	}
+	return if not $params_node;
+	for ($node =3D $params_node->firstChild; $node; $node =3D $node->nextSibl=
ing ()) {
+		my $param_type;
+		foreach $attr ($node->attributes) {
+			if ($attr->name eq "type") {
+				$param_type =3D $attr->value;
+				last;
+			}
+		}
+
+		foreach $data (@$data_list_ref) {
+			if ($param_type eq $$data[4]) {
+				$node->setAttribute ($$data[5], $$data[6]);
+			}
+		}
+	}
+}
+
+sub fixupNamespace {
+	my ($self, $ns_node) =3D @_;
+	my $node;
+	foreach $rule (@{$self->{rules}}) {
+		my ($classes_ref, $data_list_ref) =3D @$rule;
+		for ($node =3D $ns_node->firstChild; $node; $node =3D $node->nextSibling=
 ()) {
+			next if $node->nodeName ne "object";
+			my $class, $methods_ref, $attr;
+			foreach $attr ($node->attributes) {
+				if ($attr->name eq "cname") {
+					$class =3D $attr->value;
+					last;
+				}
+			}
+
+			my %classes =3D %$classes_ref;
+			$methods_ref =3D $classes{$class};
+			next if not $methods_ref;
+
+			for ($method_node =3D $node->firstChild; $method_node; $method_node =3D=
 $method_node->nextSibling ()) {
+				next if $method_node->nodeName ne "method";
+				my $method;
+				foreach $attr ($method_node->attributes) {
+					if ($attr->name eq "name") {
+						$method =3D $attr->value;
+						last;
+					}
+				}
+				next if not ${$methods_ref}{$method};
+				fixupParams ($method_node, $data_list_ref);
+			}
+		}
+	}
+}
+
+sub fixup {
+	my $doc =3D $_[0];
+	my ($api_node, $ns_node);
+	my $metadata =3D undef;
+
+	$api_node =3D $doc->documentElement;
+	return if not ($api_node and $api_node->nodeName eq "api");
+	for ($ns_node =3D $api_node->firstChild; $ns_node; $ns_node =3D $ns_node-=
>nextSibling ()) {
+		next if $ns_node->nodeName ne "namespace";
+		next if not ($ns_node->attributes and (scalar (@{$ns_node->attributes}))=
 + 1);
+		my @attrs =3D $ns_node->attributes;
+		my $namespace =3D $attrs[0]->value;
+		if (-f "$namespace.metadata") {
+			if (not ($metadata and $metadata->{namespace} eq $namespace)) {
+				$metadata =3D new Metadata ($namespace);
+			}
+			$metadata->fixupNamespace ($ns_node);
+		}
+	}
+}
+
+sub output {
+	my $self =3D $_[0];
+	$rule_num =3D 0;
+	foreach $rule (@{$self->{rules}}) {
+		print "Rule #$rule_num:\n";
+		my ($classes_ref, $data_list_ref) =3D @$rule;
+		my %classes =3D %$classes_ref;
+		my @data_list =3D @$data_list_ref;
+		foreach $class (keys (%classes)) {
+			print "\tClass $class:\n";
+			foreach $method (keys %{$classes{$class}}) {
+				print "\t\tMethod $method\n";
+			}
+		}
+		print "\tData:\n";
+		foreach $data (@data_list) {
+			printf "\t\tAdd an %s to all %s of %s %s: %s=3D%s\n",
+			       $$data[0], $$data[1], $$data[3], $$data[4], $$data[5], $$data[6]=
;
+		}
+		$rule_num++;
+	}
+}
+
+1;
Index: parser/gapi2xml.pl
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/gtk-sharp/parser/gapi2xml.pl,v
retrieving revision 1.12
diff -u -r1.12 gapi2xml.pl
--- parser/gapi2xml.pl	17 Feb 2002 20:54:54 -0000	1.12
+++ parser/gapi2xml.pl	9 Jun 2002 04:56:34 -0000
@@ -10,6 +10,7 @@
 $debug=3D1;
=20
 use XML::LibXML;
+use Metadata;
=20
 if (!$ARGV[0]) {
 	die "Usage: gapi_pp.pl <srcdir> | gapi2xml.pl <namespace> <outfile>\n";
@@ -96,7 +97,9 @@
 		}
 		$boxdef =3D~ s/\n\s*//g;
 		$boxdef =3D~ /\(\"(\w+)\"/;
-		$boxdefs{$1} =3D $boxdef;
+		my $boxtype =3D $1;
+		$boxtype =3D~ s/($ns)Type(\w+)/$ns$2/;
+		$boxdefs{$boxtype} =3D $boxdef;
 	} elsif ($line =3D~ /^(const|G_CONST_RETURN)?\s*\w+\s*\**\s*(\w+)\s*\(/) =
{
 		$fname =3D $2;
 		$fdef =3D "";
@@ -298,6 +301,10 @@
 	addFieldElems($struct_el, split(/;/, $1));
 	addFuncElems($struct_el, $key);
 }
+##############################################################
+# Add metadata
+##############################################################
+Metadata::fixup $doc;
=20
 ##############################################################
 # Output the tree

--=-aVpYgBEomaDJ/XfCSZTc--