From 4d92d54b3f2541b7dd34b8f7b1b4883ea529f15f Mon Sep 17 00:00:00 2001 From: Rachel Hestilow Date: Fri, 26 Jul 2002 06:08:52 +0000 Subject: [PATCH] 2002-07-25 Rachel Hestilow [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186 --- ChangeLog | 47 +++++ generator/BoxedGen.cs | 67 +------ generator/CallbackGen.cs | 12 ++ generator/ClassBase.cs | 90 ++++++++- generator/EnumGen.cs | 13 +- generator/IGeneratable.cs | 4 + generator/Method.cs | 16 +- generator/ObjectGen.cs | 69 +------ generator/OpaqueGen.cs | 78 ++++++++ generator/Parameters.cs | 5 +- generator/Parser.cs | 10 +- generator/Property.cs | 24 ++- generator/SignalHandler.cs | 6 +- generator/Statistics.cs | 13 +- generator/StructBase.cs | 294 +++++++----------------------- generator/StructGen.cs | 67 +------ generator/SymbolTable.cs | 50 ++++- generator/gtkapi.xml | 45 +---- glib/Boxed.cs | 42 +---- glib/Opaque.cs | 138 ++++++++++++++ glib/Value.cs | 17 ++ glue/Makefile.am | 1 - glue/textiter.c | 23 --- gnome/Program.custom | 4 +- gtk/TextIter.custom | 30 --- parser/GAPI/Metadata.pm | 16 +- parser/Metadata.pm | 16 +- parser/README | 4 +- parser/gapi2xml.pl | 1 + parser/gapi_pp.pl | 10 + sample/test/TestColorSelection.cs | 8 +- sources/README | 4 +- 32 files changed, 627 insertions(+), 597 deletions(-) create mode 100644 generator/OpaqueGen.cs create mode 100644 glib/Opaque.cs delete mode 100644 glue/textiter.c delete mode 100755 gtk/TextIter.custom diff --git a/ChangeLog b/ChangeLog index b67003260..cfab12b58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,50 @@ +2002-07-25 Rachel Hestilow + + [about 60% of the marshalling patch that I lost. + The rest to come tomorrow.] + + * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, + delete large chunks duplicated from ClassBase. + + * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. + + * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName + overload with no parameters for the "self" reference. + + * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, + FromNativeReturn. + + * generator/Method.cs: Use container_type.MarshalType, CallByName, and + SymbolTable.FromNativeReturn when generating call and import sigs. + + * generator/OpaqueGen.cs: Added. + + * generator/Property.cs: Handle boxed and opaques differently. + + * generator/SymbolTable.cs: Update for the opaque stuff and the new Return + methods. Also change GetClassGen to simply call the as operator. + + * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for + the purposes of using with Value. + + * glib/Opaque.cs: Added. New base class for opaque structs. + + * glue/textiter.c, gtk/TextIter.custom: Remove. + + * gnome/Program.cs: Update for new struct marshalling. + + * parser/Metadata.pm: Use our own getChildrenByTagName. + + * parser/README: Update for new requirements (was out of sync with + build.pl) + + * parser/gapi2xml.pl: Hide struct like const in field elements. + + * parser/gapi_pp.pl: Handle embedded union fields (poorly). + + * sample/test/TestColorSelection.cs: Comment out null color tests + for now. + 2002-07-24 Mike Kestner * generator/SignalHandler.cs : use ref parameters in signal cb's. diff --git a/generator/BoxedGen.cs b/generator/BoxedGen.cs index d7bc4435d..3304bdfc8 100644 --- a/generator/BoxedGen.cs +++ b/generator/BoxedGen.cs @@ -1,13 +1,12 @@ -// GtkSharp.Generation.BoxedGen.cs - The Boxed Type Generatable. +// GtkSharp.Generation.BoxedGen.cs - The Boxed Generatable. // // Author: Mike Kestner // -// (c) 2001-2002 Mike Kestner +// (c) 2001 Mike Kestner namespace GtkSharp.Generation { using System; - using System.Collections; using System.IO; using System.Xml; @@ -15,67 +14,9 @@ namespace GtkSharp.Generation { public BoxedGen (XmlElement ns, XmlElement elem) : base (ns, elem) {} - public override String FromNative(String var) + public override void Generate () { - return "(" + QualifiedName + ") GLib.Boxed.FromNative(" + var + ")"; - } - - public void Generate () - { - StreamWriter sw = CreateWriter (); - - sw.WriteLine ("\tusing System;"); - sw.WriteLine ("\tusing System.Collections;"); - sw.WriteLine ("\tusing System.Runtime.InteropServices;"); - sw.WriteLine (); - - sw.WriteLine("\t\t/// " + Name + " Boxed Struct"); - sw.WriteLine("\t\t/// "); - sw.WriteLine("\t\t/// "); - - sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]"); - sw.WriteLine ("\tpublic class " + Name + " : GLib.Boxed {"); - sw.WriteLine (); - - sw.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}"); - sw.WriteLine(); - - Hashtable clash_map = new Hashtable(); - - foreach (XmlNode node in Elem.ChildNodes) { - if (!(node is XmlElement)) continue; - XmlElement member = (XmlElement) node; - - switch (node.Name) { - case "field": - Statistics.IgnoreCount++; - // GenField(member, sw); - break; - - case "callback": - Statistics.IgnoreCount++; - break; - - case "constructor": - if (!GenCtor(member, sw, clash_map)) { - Console.WriteLine(" in boxed " + CName); - } - break; - - case "method": - //Console.WriteLine ("HIYA {0}", ((Method) member).Name); - break; - - default: - Console.WriteLine ("Unexpected node"); - break; - } - } - - GenMethods (sw, null, null, false); - AppendCustom(sw); - sw.WriteLine ("\t}"); - CloseWriter (sw); + base.Generate (); Statistics.BoxedCount++; } } diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index 0864c7321..d0dd6defd 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -27,6 +27,13 @@ namespace GtkSharp.Generation { } } + public String MarshalReturnType { + get + { + return MarshalType; + } + } + public String CallByName (String var_name) { return var_name; @@ -37,6 +44,11 @@ namespace GtkSharp.Generation { return var; } + public String FromNativeReturn(String var) + { + return FromNative (var); + } + public void Generate () { XmlElement ret_elem = Elem["return-type"]; diff --git a/generator/ClassBase.cs b/generator/ClassBase.cs index 11b4055b9..68b815326 100644 --- a/generator/ClassBase.cs +++ b/generator/ClassBase.cs @@ -17,6 +17,11 @@ namespace GtkSharp.Generation { protected Hashtable sigs = new Hashtable(); protected Hashtable methods = new Hashtable(); protected ArrayList interfaces = null; + protected ArrayList ctors = new ArrayList(); + + private bool hasDefaultConstructor = true; + private bool ctors_initted = false; + private Hashtable clash_map; public Hashtable Methods { get { @@ -64,6 +69,14 @@ namespace GtkSharp.Generation { interfaces = ParseImplements (member); break; + case "constructor": + ctors.Add (new Ctor (LibraryName, member, this)); + break; + + case "disabledefaultconstructor": + hasDefaultConstructor = false; + break; + default: break; } @@ -77,6 +90,8 @@ namespace GtkSharp.Generation { case "property": case "signal": case "implements": + case "constructor": + case "disabledefaultconstructor": return true; default: @@ -91,16 +106,33 @@ namespace GtkSharp.Generation { } } + public virtual String MarshalReturnType { + get + { + return "IntPtr"; + } + } + public virtual String CallByName (String var_name) { return var_name + ".Handle"; } + public virtual String CallByName () + { + return "Handle"; + } + public virtual String FromNative(String var) { return "(" + QualifiedName + ") GLib.Object.GetObject(" + var + ")"; } - + + public virtual String FromNativeReturn(String var) + { + return FromNative (var); + } + protected void GenProperties (StreamWriter sw) { if (props == null) @@ -263,5 +295,61 @@ namespace GtkSharp.Generation { else return false; } + + public ArrayList Ctors { get { return ctors; } } + + private void InitializeCtors () + { + if (ctors_initted) + return; + + clash_map = new Hashtable(); + + if (ctors != null) { + bool has_preferred = false; + foreach (Ctor ctor in ctors) { + if (ctor.Validate ()) { + ctor.InitClashMap (clash_map); + if (ctor.Preferred) + has_preferred = true; + } + else + Console.WriteLine(" in Object " + Name); + } + + if (!has_preferred && ctors.Count > 0) + ((Ctor) ctors[0]).Preferred = true; + + foreach (Ctor ctor in ctors) + if (ctor.Validate ()) { + ctor.Initialize (clash_map); + } + } + + ctors_initted = true; + } + + protected virtual void GenCtors (StreamWriter sw) + { + ClassBase klass = this; + while (klass != null) { + klass.InitializeCtors (); + klass = klass.Parent; + } + + if (ctors != null) { + foreach (Ctor ctor in ctors) { + if (ctor.Validate ()) + ctor.Generate (sw); + } + } + + if (!clash_map.ContainsKey("") && hasDefaultConstructor) { + sw.WriteLine("\t\tprotected " + Name + "() : base(){}"); + sw.WriteLine(); + } + + } + } } diff --git a/generator/EnumGen.cs b/generator/EnumGen.cs index 120bc7ad1..e92660d2b 100644 --- a/generator/EnumGen.cs +++ b/generator/EnumGen.cs @@ -20,7 +20,13 @@ namespace GtkSharp.Generation { return "int"; } } - + public String MarshalReturnType { + get + { + return MarshalType; + } + } + public String CallByName (String var_name) { return "(int) " + var_name; @@ -31,6 +37,11 @@ namespace GtkSharp.Generation { return "(" + QualifiedName + ")" + var; } + public String FromNativeReturn(String var) + { + return FromNative (var); + } + public void Generate () { StreamWriter sw = CreateWriter (); diff --git a/generator/IGeneratable.cs b/generator/IGeneratable.cs index c5236f6ec..7554e93f5 100644 --- a/generator/IGeneratable.cs +++ b/generator/IGeneratable.cs @@ -14,6 +14,8 @@ namespace GtkSharp.Generation { String MarshalType {get;} + String MarshalReturnType {get;} + String Name {get;} String QualifiedName {get;} @@ -22,6 +24,8 @@ namespace GtkSharp.Generation { String FromNative (String var); + String FromNativeReturn (String var); + void Generate (); } } diff --git a/generator/Method.cs b/generator/Method.cs index 1f76f2459..3a5279082 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -119,7 +119,7 @@ namespace GtkSharp.Generation { } rettype = ret_elem.GetAttribute("type"); - m_ret = SymbolTable.GetMarshalType(rettype); + m_ret = SymbolTable.GetMarshalReturnType(rettype); s_ret = SymbolTable.GetCSType(rettype); cname = elem.GetAttribute("cname"); bool is_shared = elem.HasAttribute("shared"); @@ -140,12 +140,12 @@ namespace GtkSharp.Generation { if (parms != null) { parms.CreateSignature (is_set); sig = "(" + parms.Signature + ")"; - isig = "(" + (is_shared ? "" : "IntPtr raw, ") + parms.ImportSig + ");"; - call = "(" + (is_shared ? "" : "Handle, ") + parms.CallString + ")"; + isig = "(" + (is_shared ? "" : container_type.MarshalType + " raw, ") + parms.ImportSig + ");"; + call = "(" + (is_shared ? "" : container_type.CallByName () + ", ") + parms.CallString + ")"; } else { sig = "()"; - isig = "(" + (is_shared ? "" : "IntPtr raw") + ");"; - call = "(" + (is_shared ? "" : "Handle") + ")"; + isig = "(" + (is_shared ? "" : container_type.MarshalType + " raw") + ");"; + call = "(" + (is_shared ? "" : container_type.CallByName ()) + ")"; } initialized = true; @@ -343,14 +343,14 @@ namespace GtkSharp.Generation { if (m_ret == "void") { sw.WriteLine(cname + call + ";"); } else { - if (SymbolTable.IsObject (rettype)) + if (SymbolTable.IsObject (rettype) || SymbolTable.IsOpaque (rettype)) { sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";"); - sw.WriteLine(indent +"\t\t\t" + s_ret + " ret = " + SymbolTable.FromNative(rettype, "raw_ret") + ";"); + sw.WriteLine(indent +"\t\t\t" + s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, "raw_ret") + ";"); sw.WriteLine(indent + "\t\t\tif (ret == null) ret = new " + s_ret + "(raw_ret);"); } else - sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNative(rettype, cname + call) + ";"); + sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, cname + call) + ";"); } if (parms != null) diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index c1d2d8c84..7bf75947d 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -13,11 +13,7 @@ namespace GtkSharp.Generation { public class ObjectGen : ClassBase, IGeneratable { - private ArrayList ctors = new ArrayList(); private ArrayList strings = new ArrayList(); - private bool hasDefaultConstructor = true; - private bool ctors_initted = false; - private Hashtable clash_map; public ObjectGen (XmlElement ns, XmlElement elem) : base (ns, elem) { @@ -32,14 +28,6 @@ namespace GtkSharp.Generation { Statistics.IgnoreCount++; break; - case "constructor": - ctors.Add (new Ctor (LibraryName, member, this)); - break; - - case "disabledefaultconstructor": - hasDefaultConstructor = false; - break; - case "static-string": strings.Add (node); break; @@ -177,65 +165,16 @@ namespace GtkSharp.Generation { return true; } - - public ArrayList Ctors { get { return ctors; } } - - private void InitializeCtors () - { - if (ctors_initted) - return; - - clash_map = new Hashtable(); - - if (ctors != null) { - bool has_preferred = false; - foreach (Ctor ctor in ctors) { - if (ctor.Validate ()) { - ctor.InitClashMap (clash_map); - if (ctor.Preferred) - has_preferred = true; - } - else - Console.WriteLine(" in Object " + Name); - } - - if (!has_preferred && ctors.Count > 0) - ((Ctor) ctors[0]).Preferred = true; - - foreach (Ctor ctor in ctors) - if (ctor.Validate ()) { - ctor.Initialize (clash_map); - } - } - - ctors_initted = true; - } - - private void GenCtors (StreamWriter sw) + + protected override void GenCtors (StreamWriter sw) { if (!Elem.HasAttribute("parent")) return; - ObjectGen klass = this; - while (klass != null) { - klass.InitializeCtors (); - klass = (ObjectGen) klass.Parent; - } - + sw.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}"); sw.WriteLine(); - if (ctors != null) { - foreach (Ctor ctor in ctors) { - if (ctor.Validate ()) - ctor.Generate (sw); - } - } - - if (!clash_map.ContainsKey("") && hasDefaultConstructor) { - sw.WriteLine("\t\tprotected " + Name + "() : base(){}"); - sw.WriteLine(); - } - + base.GenCtors (sw); } } } diff --git a/generator/OpaqueGen.cs b/generator/OpaqueGen.cs new file mode 100644 index 000000000..ff5c54e6c --- /dev/null +++ b/generator/OpaqueGen.cs @@ -0,0 +1,78 @@ +// GtkSharp.Generation.ObjectGen.cs - The Object Generatable. +// +// Author: Mike Kestner +// +// (c) 2001-2002 Mike Kestner + +namespace GtkSharp.Generation { + + using System; + using System.Collections; + using System.IO; + using System.Xml; + + public class OpaqueGen : ClassBase, IGeneratable { + + public OpaqueGen (XmlElement ns, XmlElement elem) : base (ns, elem) + { + } + + public override String FromNative(String var) + { + return "(" + QualifiedName + ") GLib.Opaque.GetOpaque(" + var + ")"; + } + + public override String FromNativeReturn(String var) + { + return FromNative (var); + } + + public void Generate () + { + StreamWriter sw = CreateWriter (); + + sw.WriteLine ("\tusing System;"); + sw.WriteLine ("\tusing System.Collections;"); + sw.WriteLine ("\tusing System.Runtime.InteropServices;"); + sw.WriteLine (); + + sw.WriteLine("\t\t/// " + Name + " Opaque Struct"); + sw.WriteLine("\t\t/// "); + sw.WriteLine("\t\t/// "); + sw.Write ("\tpublic class {0} : GLib.Opaque", Name); + sw.WriteLine (" {"); + sw.WriteLine (); + + GenMethods (sw, null, null, true); + GenCtors (sw); + + AppendCustom(sw); + + sw.WriteLine ("\t}"); + + CloseWriter (sw); + Statistics.OpaqueCount++; + } + + private bool Validate () + { + if (methods != null) + foreach (Method method in methods.Values) + if (!method.Validate()) { + Console.WriteLine ("in Opaque" + QualifiedName); + return false; + } + return true; + } + + protected override void GenCtors (StreamWriter sw) + { + sw.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}"); + sw.WriteLine(); + + base.GenCtors (sw); + } + + } +} + diff --git a/generator/Parameters.cs b/generator/Parameters.cs index fb149d3d6..37847567c 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -225,6 +225,9 @@ namespace GtkSharp.Generation { call_string += call_parm; } import_sig += (m_type + " " + name); + // FIXME: lame + call_string = call_string.Replace ("out ref", "ref"); + import_sig = import_sig.Replace ("out ref", "ref"); i++; } @@ -247,7 +250,7 @@ namespace GtkSharp.Generation { sw.WriteLine (indent + "\t\t\t" + type + " " + name + ";"); } - if ((is_get || (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out")) && (SymbolTable.IsObject (c_type) || SymbolTable.IsBoxed (c_type))) { + if ((is_get || (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out")) && (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type))) { sw.WriteLine(indent + "\t\t\t" + name + " = new " + type + "();"); } } diff --git a/generator/Parser.cs b/generator/Parser.cs index 94aaa76e2..29b22c14b 100644 --- a/generator/Parser.cs +++ b/generator/Parser.cs @@ -72,7 +72,10 @@ namespace GtkSharp.Generation { break; case "boxed": - SymbolTable.AddType (new BoxedGen (ns, elem)); + if (elem.HasAttribute ("opaque")) + SymbolTable.AddType (new OpaqueGen (ns, elem)); + else + SymbolTable.AddType (new BoxedGen (ns, elem)); break; case "callback": @@ -92,7 +95,10 @@ namespace GtkSharp.Generation { break; case "struct": - SymbolTable.AddType (new StructGen (ns, elem)); + if (elem.HasAttribute ("opaque")) + SymbolTable.AddType (new OpaqueGen (ns, elem)); + else + SymbolTable.AddType (new StructGen (ns, elem)); break; default: diff --git a/generator/Property.cs b/generator/Property.cs index 7ad20e11c..b6b9ee57b 100644 --- a/generator/Property.cs +++ b/generator/Property.cs @@ -77,6 +77,8 @@ namespace GtkSharp.Generation { v_type = "(GLib.Object)"; } else if (SymbolTable.IsBoxed (c_type)) { v_type = "(GLib.Boxed)"; + } else if (SymbolTable.IsOpaque (c_type)) { + v_type = "(GLib.Opaque)"; } if (elem.HasAttribute("construct-only") && !elem.HasAttribute("readable")) { @@ -93,19 +95,21 @@ namespace GtkSharp.Generation { sw.WriteLine("\t\t\tget {"); sw.WriteLine("\t\t\t\tGLib.Value val = new GLib.Value (Handle, " + cname + ");"); sw.WriteLine("\t\t\t\tGetProperty(" + cname + ", val);"); - if (SymbolTable.IsObject (c_type)) - { + if (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type)) { sw.WriteLine("\t\t\t\tSystem.IntPtr raw_ret = (System.IntPtr) (GLib.UnwrappedObject) val;"); - sw.WriteLine("\t\t\t\t" + cs_type + " ret = " + SymbolTable.FromNative(c_type, "raw_ret") + ";"); + sw.WriteLine("\t\t\t\t" + cs_type + " ret = " + SymbolTable.FromNativeReturn(c_type, "raw_ret") + ";"); sw.WriteLine("\t\t\t\tif (ret == null) ret = new " + cs_type + "(raw_ret);"); - } - else { + } else { sw.Write("\t\t\t\t" + cs_type + " ret = "); - sw.Write ("(" + cs_type + ") "); - if (v_type != "") { - sw.Write(v_type + " "); + if (SymbolTable.IsBoxed (c_type)) { + sw.WriteLine ("({0}) (({1} val).Obj);", cs_type, v_type); + } else { + sw.Write ("(" + cs_type + ") "); + if (v_type != "") { + sw.Write(v_type + " "); + } + sw.WriteLine("val;"); } - sw.WriteLine("val;"); } sw.WriteLine("\t\t\t\treturn ret;"); @@ -117,6 +121,8 @@ namespace GtkSharp.Generation { sw.Write("\t\t\t\tSetProperty(" + cname + ", new GLib.Value("); if (SymbolTable.IsEnum(c_type)) { sw.WriteLine("Handle, " + cname + ", new GLib.EnumWrapper ((int) value)));"); + } else if (SymbolTable.IsBoxed (c_type)) { + sw.WriteLine("Handle, " + cname + ", new GLib.Boxed (value)));"); } else { if (v_type != "") { sw.Write(v_type + " "); diff --git a/generator/SignalHandler.cs b/generator/SignalHandler.cs index 5e6c50d8a..637362705 100644 --- a/generator/SignalHandler.cs +++ b/generator/SignalHandler.cs @@ -31,7 +31,7 @@ namespace GtkSharp.Generation { } string s_ret = SymbolTable.GetCSType(retval); - string p_ret = SymbolTable.GetMarshalType(retval); + string p_ret = SymbolTable.GetMarshalReturnType(retval); if ((s_ret == "") || (p_ret == "")) { Console.Write("Funky type: " + retval); return ""; @@ -66,8 +66,6 @@ namespace GtkSharp.Generation { pinv += ", "; } - if (SymbolTable.IsStruct(type)) - pinv += "ref "; pinv += (ptype + " arg" + pcnt); parms.Add(type); if (SymbolTable.IsObject(type)) { @@ -156,7 +154,7 @@ namespace GtkSharp.Generation { string ctype = (string) parms[idx]; sw.WriteLine("\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";"); ClassBase wrapper = SymbolTable.GetClassGen (ctype); - if ((wrapper != null && !(wrapper is InterfaceGen)) || SymbolTable.IsManuallyWrapped (ctype) || SymbolTable.IsBoxed (ctype)) { + if ((wrapper != null && ((wrapper is ObjectGen) || (wrapper is OpaqueGen))) || SymbolTable.IsManuallyWrapped (ctype)) { sw.WriteLine("\t\t\tif (args.Args[" + (idx-1) + "] == null)"); sw.WriteLine("\t\t\t\targs.Args[{0}] = new {1}(arg{2});", idx-1, SymbolTable.GetCSType (ctype), idx); } diff --git a/generator/Statistics.cs b/generator/Statistics.cs index 490070e6c..ce3e0eb0e 100644 --- a/generator/Statistics.cs +++ b/generator/Statistics.cs @@ -16,6 +16,7 @@ namespace GtkSharp.Generation { static int objects = 0; static int structs = 0; static int boxed = 0; + static int opaques = 0; static int interfaces = 0; static int methods = 0; static int ctors = 0; @@ -69,6 +70,15 @@ namespace GtkSharp.Generation { } } + public static int OpaqueCount { + get { + return opaques; + } + set { + opaques = value; + } + } + public static int CtorCount { get { return ctors; @@ -138,6 +148,7 @@ namespace GtkSharp.Generation { Console.WriteLine("\tEnums: " + enums); Console.WriteLine("\tStructs: " + structs); Console.WriteLine("\tBoxed: " + boxed); + Console.WriteLine("\tOpaques: " + opaques); Console.WriteLine("\tInterfaces: " + interfaces); Console.WriteLine("\tCallbacks: " + cbs); Console.WriteLine("\tObjects: " + objects); @@ -147,7 +158,7 @@ namespace GtkSharp.Generation { Console.WriteLine("\tConstructors: " + ctors); Console.WriteLine("\tThrottled: " + throttled); Console.WriteLine("\tIgnored: " + ignored); - Console.WriteLine("Total Nodes: " + (enums+structs+boxed+interfaces+cbs+objects+props+sigs+methods+ctors+throttled+ignored)); + Console.WriteLine("Total Nodes: " + (enums+structs+boxed+opaques+interfaces+cbs+objects+props+sigs+methods+ctors+throttled+ignored)); } } } diff --git a/generator/StructBase.cs b/generator/StructBase.cs index c2808d735..5b402ccea 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -16,62 +16,38 @@ namespace GtkSharp.Generation { public StructBase (XmlElement ns, XmlElement elem) : base (ns, elem) {} - protected bool GenCtor(XmlElement ctor, StreamWriter sw, Hashtable clash_map) + public override String MarshalType { + get + { + return "ref " + QualifiedName; + } + } + + public override String MarshalReturnType { + get + { + return "IntPtr"; + } + } + + public override String CallByName (String var_name) { - String sig, isig, call, sigtypes; - XmlElement parms = ctor["parameters"]; - - if (parms == null) { - call = sig = "()"; - isig = "();"; - sigtypes = ""; - } else if (GetSignature(parms, out sig, out sigtypes) && - GetImportSig(parms, out isig) && - GetCallString(parms, out call)) { - sig = "(" + sig + ")"; - isig = "(" + isig + ");"; - call = "(" + call + ")"; - } else { - Console.Write("ctor "); - Statistics.ThrottledCount++; - return false; - } - - bool clash = false; - if (clash_map.ContainsKey(sigtypes)) { - clash = true; - } else { - clash_map[sigtypes] = ctor; - } - - String cname = ctor.GetAttribute("cname"); - - sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\")]"); - sw.WriteLine("\t\tstatic extern IntPtr " + cname + isig); - sw.WriteLine(); - - if (clash) { - String mname = cname.Substring(cname.IndexOf("new")); - mname = mname.Substring(0,1).ToUpper() + mname.Substring(1); - int idx; - while ((idx = mname.IndexOf("_")) > 0) { - mname = mname.Substring(0, idx) + mname.Substring(idx+1, 1).ToUpper() + mname.Substring(idx+2); - } - - sw.WriteLine("\t\tpublic static " + Name + " " + mname + sig); - sw.WriteLine("\t\t{"); - sw.WriteLine("\t\t\treturn new " + Name + "(" + cname + call + ");"); - } else { - sw.WriteLine("\t\tpublic " + Name + sig); - sw.WriteLine("\t\t{"); - sw.WriteLine("\t\t\tRaw = " + cname + call + ";"); - } - - sw.WriteLine("\t\t}"); - sw.WriteLine(); - - Statistics.CtorCount++; - return true; + return "ref " + var_name; + } + + public override String CallByName () + { + return "ref this"; + } + + public override String FromNative(String var) + { + return var; + } + + public override String FromNativeReturn(String var) + { + return "new " + QualifiedName + " (" + var + ")"; } protected bool GenField (XmlElement field, StreamWriter sw) @@ -101,182 +77,6 @@ namespace GtkSharp.Generation { return true; } - protected bool GenMethod(XmlElement method, StreamWriter sw) - { - String sig, isig, call, sigtypes; - XmlElement parms = method["parameters"]; - - if (parms == null) { - call = "(Handle)"; - sig = "()"; - isig = "(IntPtr raw);"; - sigtypes = ""; - } else if (GetSignature(parms, out sig, out sigtypes) && - GetImportSig(parms, out isig) && - GetCallString(parms, out call)) { - sig = "(" + sig + ")"; - isig = "(IntPtr raw, " + isig + ");"; - call = "(Handle, " + call + ")"; - } else { - Console.Write("method "); - Statistics.ThrottledCount++; - return false; - } - - XmlElement ret_elem = method["return-type"]; - if (ret_elem == null) { - Console.Write("Missing return type in method "); - Statistics.ThrottledCount++; - return false; - } - - String rettype = ret_elem.GetAttribute("type"); - - String m_ret = SymbolTable.GetMarshalType(rettype); - String s_ret = SymbolTable.GetCSType(rettype); - if (m_ret == "" || s_ret == "") { - Console.Write("rettype: " + rettype + " method "); - Statistics.ThrottledCount++; - return false; - } - - String cname = method.GetAttribute("cname"); - String name = method.GetAttribute("name"); - - if (cname[0] == '_') { - Statistics.ThrottledCount++; - return true; - } - - sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\")]"); - sw.Write("\t\tstatic extern " + m_ret + " " + cname + isig); - sw.WriteLine(); - - sw.WriteLine("\t\tpublic " + s_ret + " " + name + sig); - sw.WriteLine("\t\t{"); - sw.Write("\t\t\t"); - if (m_ret == "void") { - sw.WriteLine(cname + call + ";"); - } else { - sw.WriteLine("return " + SymbolTable.FromNative(rettype, cname + call) + ";"); - } - - sw.WriteLine("\t\t}"); - sw.WriteLine(); - - Statistics.MethodCount++; - return true; - } - - private bool GetCallString(XmlElement parms, out String call) - { - call = ""; - - bool need_comma = false; - - foreach (XmlNode parm in parms.ChildNodes) { - if (!(parm is XmlElement) || parm.Name != "parameter") { - Console.Write(parm.Name + " node "); - return false; - } - - XmlElement elem = (XmlElement) parm; - String type = elem.GetAttribute("type"); - String name = elem.GetAttribute("name"); - name = MangleName(name); - String call_parm = SymbolTable.CallByName(type, name); - - if (call_parm == "") { - Console.Write("Name: " + name + " Type: " + type + " "); - return false; - } - - if (need_comma) { - call += ", "; - } else { - need_comma = true; - } - call += call_parm; - } - - return true; - } - - private bool GetImportSig(XmlElement parms, out String isig) - { - isig = ""; - - bool need_comma = false; - - foreach (XmlNode parm in parms.ChildNodes) { - if (!(parm is XmlElement) || parm.Name != "parameter") { - continue; - } - - XmlElement elem = (XmlElement) parm; - String type = elem.GetAttribute("type"); - String m_type = SymbolTable.GetMarshalType(type); - String name = elem.GetAttribute("name"); - name = MangleName(name); - - if ((m_type == "") || (name == "")) { - Console.Write("Name: " + name + " Type: " + type + " "); - return false; - } - - if (elem.HasAttribute("array")) { - m_type += "[]"; - } - - if (need_comma) { - isig += ", "; - } else { - need_comma = true; - } - isig += (m_type + " " + name); - } - - return true; - } - - private bool GetSignature(XmlElement parms, out String sig, out String sigtypes) - { - sigtypes = sig = ""; - bool need_comma = false; - - foreach (XmlNode parm in parms.ChildNodes) { - if (parm.Name != "parameter") { - continue; - } - - XmlElement elem = (XmlElement) parm; - String type = elem.GetAttribute("type"); - String cs_type = SymbolTable.GetCSType(type); - String name = elem.GetAttribute("name"); - name = MangleName(name); - - if ((cs_type == "") || (name == "")) { - Console.Write("Name: " + name + " Type: " + type + " "); - return false; - } - - if (elem.HasAttribute("array")) { - cs_type += "[]"; - } - - if (need_comma) { - sig += ", "; - sigtypes += ":"; - } else { - need_comma = true; - } - sig += (cs_type + " " + name); - sigtypes += cs_type; - } - - return true; - } - private String MangleName(String name) { if (name == "string") { @@ -291,6 +91,38 @@ namespace GtkSharp.Generation { return name; } } + + public virtual void Generate () + { + StreamWriter sw = CreateWriter (); + + sw.WriteLine ("\tusing System;"); + sw.WriteLine ("\tusing System.Collections;"); + sw.WriteLine ("\tusing System.Runtime.InteropServices;"); + sw.WriteLine (); + + sw.WriteLine("\t\t/// " + Name + " Struct "); + sw.WriteLine("\t\t/// "); + sw.WriteLine("\t\t/// "); + + sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]"); + sw.WriteLine ("\tpublic struct " + Name + " {"); + sw.WriteLine (); + + GenCtors (sw); + AppendCustom(sw); + + sw.WriteLine ("\t}"); + CloseWriter (sw); + } + + protected override void GenCtors (StreamWriter sw) + { + sw.WriteLine("\t\tpublic " + Name + "(IntPtr raw) {}"); + sw.WriteLine(); + //base.GenCtors (sw); + } + } } diff --git a/generator/StructGen.cs b/generator/StructGen.cs index 8e36d0986..6d2942b55 100644 --- a/generator/StructGen.cs +++ b/generator/StructGen.cs @@ -14,72 +14,9 @@ namespace GtkSharp.Generation { public StructGen (XmlElement ns, XmlElement elem) : base (ns, elem) {} - public override string MarshalType { - get - { - return QualifiedName; - } - } - - public override String CallByName (String var_name) + public override void Generate () { - return var_name; - } - - public override String FromNative(String var) - { - return var; - } - - public void Generate () - { - StreamWriter sw = CreateWriter (); - - sw.WriteLine ("\tusing System;"); - sw.WriteLine ("\tusing System.Collections;"); - sw.WriteLine ("\tusing System.Runtime.InteropServices;"); - sw.WriteLine (); - - sw.WriteLine("\t\t/// " + Name + " Struct "); - sw.WriteLine("\t\t/// "); - sw.WriteLine("\t\t/// "); - - sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]"); - sw.WriteLine ("\tpublic struct " + Name + " {"); - sw.WriteLine (); - - foreach (XmlNode node in Elem.ChildNodes) { - if (!(node is XmlElement)) continue; - XmlElement member = (XmlElement) node; - - switch (node.Name) { - case "field": - Statistics.IgnoreCount++; - // GenField(member, sw); - break; - - case "callback": - Statistics.IgnoreCount++; - break; - - case "constructor": - Statistics.IgnoreCount++; - break; - - case "method": - Statistics.IgnoreCount++; - break; - - default: - Console.WriteLine ("Unexpected node"); - break; - } - } - - AppendCustom(sw); - - sw.WriteLine ("\t}"); - CloseWriter (sw); + base.Generate (); Statistics.StructCount++; } } diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 0fae55916..764609d2b 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -123,7 +123,17 @@ namespace GtkSharp.Generation { return type; } + public static string FromNativeReturn(string c_type, string val) + { + return FromNative (c_type, val, true); + } + public static string FromNative(string c_type, string val) + { + return FromNative (c_type, val, false); + } + + public static string FromNative(string c_type, string val, bool ret) { c_type = Trim(c_type); c_type = DeAlias(c_type); @@ -131,7 +141,10 @@ namespace GtkSharp.Generation { return val; } else if (complex_types.ContainsKey(c_type)) { IGeneratable gen = (IGeneratable) complex_types[c_type]; - return gen.FromNative(val); + if (ret) + return gen.FromNativeReturn(val); + else + return gen.FromNative(val); } else if (manually_wrapped_types.ContainsKey(c_type)) { // FIXME: better way of handling this? if (c_type == "GSList") { @@ -184,7 +197,17 @@ namespace GtkSharp.Generation { } } + public static string GetMarshalReturnType(string c_type) + { + return GetMarshalType (c_type, true); + } + public static string GetMarshalType(string c_type) + { + return GetMarshalType (c_type, false); + } + + public static string GetMarshalType(string c_type, bool ret) { c_type = Trim(c_type); c_type = DeAlias(c_type); @@ -194,7 +217,10 @@ namespace GtkSharp.Generation { return "IntPtr"; } else if (complex_types.ContainsKey(c_type)) { IGeneratable gen = (IGeneratable) complex_types[c_type]; - return gen.MarshalType; + if (ret) + return gen.MarshalReturnType; + else + return gen.MarshalType; } else { return ""; } @@ -215,7 +241,20 @@ namespace GtkSharp.Generation { return ""; } } - + + public static bool IsOpaque(string c_type) + { + c_type = Trim(c_type); + c_type = DeAlias(c_type); + if (complex_types.ContainsKey(c_type)) { + IGeneratable gen = (IGeneratable) complex_types[c_type]; + if (gen is OpaqueGen) { + return true; + } + } + return false; + } + public static bool IsBoxed(string c_type) { c_type = Trim(c_type); @@ -272,10 +311,7 @@ namespace GtkSharp.Generation { { c_type = Trim(c_type); c_type = DeAlias(c_type); - if (IsInterface(c_type) || IsObject (c_type)) { - return (ClassBase) complex_types[c_type]; - } - return null; + return (complex_types[c_type] as ClassBase); } public static bool IsObject(string c_type) diff --git a/generator/gtkapi.xml b/generator/gtkapi.xml index 2fb83a7cf..085ec3484 100644 --- a/generator/gtkapi.xml +++ b/generator/gtkapi.xml @@ -1,4 +1,4 @@ - + @@ -1659,7 +1659,7 @@ - + @@ -1674,12 +1674,7 @@ - - - - - - + @@ -3367,10 +3362,7 @@ - - - - + @@ -10425,7 +10417,7 @@ - + @@ -13829,10 +13821,7 @@ - - - - + @@ -14881,12 +14870,7 @@ - - - - - - + @@ -14943,18 +14927,7 @@ - - - - - - - - - - - - + @@ -17664,6 +17637,8 @@ + + diff --git a/glib/Boxed.cs b/glib/Boxed.cs index bb854bb62..e0423f53f 100644 --- a/glib/Boxed.cs +++ b/glib/Boxed.cs @@ -16,11 +16,8 @@ namespace GLib { /// An abstract base class to derive structures and marshal them. /// - public abstract class Boxed { - - private IntPtr raw; - - public Boxed () : this (IntPtr.Zero) {} + public class Boxed { + object raw; /// /// Boxed Constructor @@ -30,7 +27,7 @@ namespace GLib { /// Constructs a Boxed type from a raw ref. /// - public Boxed (IntPtr raw) + public Boxed (object o) { this.raw = raw; } @@ -43,7 +40,7 @@ namespace GLib { /// Gets a marshallable IntPtr. /// - public virtual IntPtr Handle { + public virtual object Obj { get { return raw; } @@ -51,36 +48,5 @@ namespace GLib { raw = value; } } - - /// - /// Raw Property - /// - /// - /// - /// Gets or sets a marshallable IntPtr. - /// - - protected IntPtr Raw { - get { - return raw; - } - set { - raw = value; - } - } - - /// - /// FromNative Method - /// - /// - /// - /// Gets a Boxed type from a raw IntPtr. - /// - - public static GLib.Boxed FromNative (IntPtr raw) - { - // FIXME: - return null; - } } } diff --git a/glib/Opaque.cs b/glib/Opaque.cs new file mode 100644 index 000000000..32888c30f --- /dev/null +++ b/glib/Opaque.cs @@ -0,0 +1,138 @@ +// Object.cs - GObject class wrapper implementation +// +// Authors: Bob Smith +// Mike Kestner +// +// (c) 2001 Bob Smith and Mike Kestner + +namespace GLib { + + using System; + using System.Collections; + using System.ComponentModel; + using System.Runtime.InteropServices; + + /// + /// Object Class + /// + /// + /// + /// Wrapper class for GObject. + /// + + public class Opaque : IWrapper { + + // Private class and instance members + IntPtr _obj; + EventHandlerList _events; + Hashtable Data; + static Hashtable Opaques = new Hashtable(); + + /// + /// GetObject Shared Method + /// + /// + /// + /// Used to obtain a CLI typed object associated with a + /// given raw object pointer. This method is primarily + /// used to wrap object references that are returned + /// by either the signal system or raw class methods that + /// return GObject references. + /// + /// + /// + /// The wrapper instance. + /// + + public static Opaque GetOpaque(IntPtr o) + { + Opaque obj = (Opaque)Opaques[(int)o]; + if (obj != null) return obj; + return null; //FIXME: Call TypeParser here eventually. + } + + /// + /// Object Constructor + /// + /// + /// + /// Dummy constructor needed for derived classes. + /// + + public Opaque () {} + + /// + /// Object Constructor + /// + /// + /// + /// Creates an object from a raw object reference. + /// + + public Opaque (IntPtr raw) + { + Raw = raw; + } + + /// + /// Raw Property + /// + /// + /// + /// The raw GObject reference associated with this wrapper. + /// Only subclasses of Object can access this read/write + /// property. For public read-only access, use the + /// Handle property. + /// + + protected IntPtr Raw { + get { + return _obj; + } + set { + Opaques [value] = this; + _obj = value; + } + } + + /// + /// Handle Property + /// + /// + /// + /// The raw GObject reference associated with this object. + /// Subclasses can use Raw property for read/write + /// access. + /// + + public IntPtr Handle { + get { + return _obj; + } + set { + _obj = value; + } + } + + public override bool Equals (object o) + { + if (!(o is Opaque)) + return false; + + return (Handle == ((Opaque) o).Handle); + } + + /// + /// GetHashCode Method + /// + /// + /// + /// Calculates a hashing value. + /// + + public override int GetHashCode () + { + return Handle.GetHashCode (); + } + } +} diff --git a/glib/Value.cs b/glib/Value.cs index 7559cdd90..d1c91956c 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -95,6 +95,18 @@ namespace GLib { /// public Value (GLib.Boxed val) + { + _val = gtksharp_value_create(TypeFundamentals.TypeBoxed); + //g_value_set_boxed (_val, val.Handle); + } + + public Value (IntPtr obj, string prop_name, Boxed val) + { + _val = gtksharp_value_create_from_property (obj, prop_name); + //g_value_set_boxed (_val, val.Handle); + } + + public Value (GLib.Opaque val) { _val = gtksharp_value_create(TypeFundamentals.TypeBoxed); g_value_set_boxed (_val, val.Handle); @@ -259,6 +271,11 @@ namespace GLib { [DllImport("gobject-2.0")] static extern IntPtr g_value_get_boxed (IntPtr val); + public static explicit operator GLib.Opaque (Value val) + { + return GLib.Opaque.GetOpaque (g_value_get_boxed (val._val)); + } + /// /// Value to Boxed Conversion /// diff --git a/glue/Makefile.am b/glue/Makefile.am index e38e0d6c0..c49651b18 100644 --- a/glue/Makefile.am +++ b/glue/Makefile.am @@ -2,7 +2,6 @@ lib_LTLIBRARIES = libgtksharpglue.la BASESOURCES = \ value.c \ - textiter.c \ fileselection.c \ dialog.c \ colorseldialog.c \ diff --git a/glue/textiter.c b/glue/textiter.c deleted file mode 100644 index 5b44cba0d..000000000 --- a/glue/textiter.c +++ /dev/null @@ -1,23 +0,0 @@ -/* textiter.c : Glue to allocate GtkTextIters on the heap. - * - * Author: Rachel Hestilow - * - * 2002 Rachel Hestilow, Mike Kestner - */ - -#include - -GtkTextIter* -gtksharp_text_iter_create (void) -{ - GtkTextIter *iter = g_new0 (GtkTextIter, 1); - return iter; -} - -void -gtksharp_test_array (int len, int* types) -{ - int i; - for (i = 0; i < len; i++) - g_print ("type %i\n", types[i]); -} diff --git a/gnome/Program.custom b/gnome/Program.custom index d3b97b61f..bcfc3a353 100644 --- a/gnome/Program.custom +++ b/gnome/Program.custom @@ -19,7 +19,7 @@ struct PropertyArg { [DllImport("gtksharpglue")] static extern System.IntPtr -gtksharp_gnome_program_init (string app_id, string app_version, System.IntPtr module, int argc, string[] argv, int nargs, PropertyArg[] args); +gtksharp_gnome_program_init (string app_id, string app_version, ref ModuleInfo module, int argc, string[] argv, int nargs, PropertyArg[] args); public Program (string app_id, string app_version, ModuleInfo module, string[] argv, params object[] props) @@ -51,7 +51,7 @@ public Program (string app_id, string app_version, ModuleInfo module, /* FIXME: Is there a way to access this in .NET? */ new_argv[0] = app_id; Array.Copy (argv, 0, new_argv, 1, argv.Length); - Raw = gtksharp_gnome_program_init (app_id, app_version, module.Handle, new_argv.Length, new_argv, nargs, args); + Raw = gtksharp_gnome_program_init (app_id, app_version, ref module, new_argv.Length, new_argv, nargs, args); } public void Run () diff --git a/gtk/TextIter.custom b/gtk/TextIter.custom deleted file mode 100755 index 2ee8d9e7f..000000000 --- a/gtk/TextIter.custom +++ /dev/null @@ -1,30 +0,0 @@ -// Gtk.TextIter.custom - Gtk TextIter class customizations -// -// Author: Rachel Hestilow -// -// (c) 2001 Mike Kestner, 2002 Rachel Hestilow -// -// This code is inserted after the automatically generated code. - - - /// - /// TextIter Constructor - /// - /// - /// - /// Constructs a new TextIter. - - [DllImport("gtksharpglue")] - static extern IntPtr gtksharp_text_iter_create(); - public TextIter () : this (gtksharp_text_iter_create ()) - { - } - - [DllImport("glib-2.0")] - static extern void g_free (IntPtr mem); - - ~TextIter () - { - g_free (Handle); - } - diff --git a/parser/GAPI/Metadata.pm b/parser/GAPI/Metadata.pm index 9e96ad6ac..719842401 100644 --- a/parser/GAPI/Metadata.pm +++ b/parser/GAPI/Metadata.pm @@ -127,12 +127,26 @@ sub fixupParams { } } +sub myGetChildrenByTagName { + my ($node, $tagname) = @_; + my ($child); + my (@nodes) = (); + for ($child = $node->firstChild; $child; $child = $child->nextSibling ()) { + if ($child->nodeName eq $tagname) { + push @nodes, $child; + } + } + return @nodes; +} + sub addClassData { my ($doc, $node, $class, $data_list_ref) = @_; foreach $data (@$data_list_ref) { if ($$data[1] eq "class") { - my @nodes = $node->getChildrenByTagName ($$data[5]); + # my copy of XML::LibXML doesn't have this method. + #my @nodes = $node->getChildrenByTagName ($$data[5]); + my @nodes = myGetChildrenByTagName ($node, $$data[5]); if (0 == scalar @nodes) { print STDERR "DEBUG> $class $$data[0] $$data[1] $$data[2] $$data[3] $$data[4] $$data[5] $$data[6]\n"; diff --git a/parser/Metadata.pm b/parser/Metadata.pm index 9e96ad6ac..719842401 100644 --- a/parser/Metadata.pm +++ b/parser/Metadata.pm @@ -127,12 +127,26 @@ sub fixupParams { } } +sub myGetChildrenByTagName { + my ($node, $tagname) = @_; + my ($child); + my (@nodes) = (); + for ($child = $node->firstChild; $child; $child = $child->nextSibling ()) { + if ($child->nodeName eq $tagname) { + push @nodes, $child; + } + } + return @nodes; +} + sub addClassData { my ($doc, $node, $class, $data_list_ref) = @_; foreach $data (@$data_list_ref) { if ($$data[1] eq "class") { - my @nodes = $node->getChildrenByTagName ($$data[5]); + # my copy of XML::LibXML doesn't have this method. + #my @nodes = $node->getChildrenByTagName ($$data[5]); + my @nodes = myGetChildrenByTagName ($node, $$data[5]); if (0 == scalar @nodes) { print STDERR "DEBUG> $class $$data[0] $$data[1] $$data[2] $$data[3] $$data[4] $$data[5] $$data[6]\n"; diff --git a/parser/README b/parser/README index 2540c61f5..c0f285a88 100644 --- a/parser/README +++ b/parser/README @@ -3,9 +3,9 @@ Put source modules here to parse for the gtkapi.xml file. Currently supported: glib-2.0.3 -pango-1.0.2 +pango-1.0.3 atk-1.0.2 -gtk+-2.0.3 +gtk+-2.0.5 libgnome-2.0.1 libgnomecanvas-2.0.1 libgnomeui-2.0.1 diff --git a/parser/gapi2xml.pl b/parser/gapi2xml.pl index 2b7fa6647..7401af0af 100755 --- a/parser/gapi2xml.pl +++ b/parser/gapi2xml.pl @@ -394,6 +394,7 @@ sub addFieldElems next if ($field !~ /\S/); $field =~ s/\s+(\*+)/\1 /g; $field =~ s/const /const\-/g; + $field =~ s/struct /struct\-/g; $field =~ s/.*\*\///g; next if ($field !~ /\S/); diff --git a/parser/gapi_pp.pl b/parser/gapi_pp.pl index dad4ea5c1..d8d938bff 100755 --- a/parser/gapi_pp.pl +++ b/parser/gapi_pp.pl @@ -66,6 +66,16 @@ foreach $fname (@hdrs) { while ($line !~ /^}\s*\w+;/) {$line = ;} } elsif ($line =~ /^enum\s+\{/) { while ($line !~ /^};/) {$line = ;} + } elsif ($line =~ /(\s+)union\s*{/) { + # this is a hack for now, but I need it for the fields to work + $indent = $1; + $do_print = 1; + while ($line !~ /^$indent}\s*\w+;/) { + $line = ; + next if ($line !~ /;/); + print $line if $do_print; + $do_print = 0; + } } else { if ($braces or $line =~ /;/) { print $line; diff --git a/sample/test/TestColorSelection.cs b/sample/test/TestColorSelection.cs index 7f8d096f8..7b6cc2191 100644 --- a/sample/test/TestColorSelection.cs +++ b/sample/test/TestColorSelection.cs @@ -67,12 +67,12 @@ namespace WidgetViewer { static void Color_Selection_OK (object o, EventArgs args) { Gdk.Color selected = window.ColorSelection.CurrentColor; - +/* if (selected == null) { Console.WriteLine ("Color selection failed."); return; } - +*/ Display_Result (selected); } @@ -85,10 +85,10 @@ namespace WidgetViewer { static void Display_Result (Gdk.Color color) { - +/* if (color == null) Console.WriteLine ("Null color"); - +*/ dialog = new Dialog (); dialog.Title = "Selected Color"; diff --git a/sources/README b/sources/README index 2540c61f5..c0f285a88 100644 --- a/sources/README +++ b/sources/README @@ -3,9 +3,9 @@ Put source modules here to parse for the gtkapi.xml file. Currently supported: glib-2.0.3 -pango-1.0.2 +pango-1.0.3 atk-1.0.2 -gtk+-2.0.3 +gtk+-2.0.5 libgnome-2.0.1 libgnomecanvas-2.0.1 libgnomeui-2.0.1