From 6857128f077e7bbf2920f74465b427b442ed876e Mon Sep 17 00:00:00 2001 From: Rachel Hestilow Date: Fri, 21 Jun 2002 17:15:19 +0000 Subject: [PATCH] 2002-06-21 Rachel Hestilow * generator/ClassBase.cs: New base class for classes and interfaces. * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. * generator/ObjectGen.cs: Move half of this into ClassBase. * generator/Method.cs: Turn all applicable Get/Set functions into .NET accessors. Remove redundant == overload and move into Equals, as it was confusing "!= null". * generator/Parameters.cs: Alter signature creation to accept "is_set" option, add support for variable arguments. Add properties "Count", "IsVarArgs", "VAType". * generator/Ctor.cs: Fixup for changes in Parameters (indenting, signature creation). * generator/Signal.cs: Support generating declarations. * generator/SymbolTable: Change GetObjectGen to GetClassGen. * glib/IWrapper.cs: Move "Handle" declaration to here, so both classes and interfaces can benefit from it. * glib/Object.cs: Inherit from IWrapper.cs * parser/Metadata.pm: Support attribute changes on constructors, methods, signals, and paramater lists. * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" functions here. * parser/gapi_pp.pl: Remove boxed_type_register check, as it will be caught in the init funcs. * parser/Atk.metadata: Added. * parser/Gtk.metadata: Add all needed signal/method collision renames. Rename GtkEditable.Editable accessors to IsEditable, as .NET does not like accessors with the same name as their declaring type. Tag TreeStore constructor as varargs. * samples/ButtonApp.cs: s/EmitAdd/Add. * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. svn path=/trunk/gtk-sharp/; revision=5394 --- ChangeLog | 48 ++ generator/ClassBase.cs | 149 +++++++ generator/Ctor.cs | 19 +- generator/InterfaceGen.cs | 37 +- generator/Method.cs | 276 +++++++++--- generator/ObjectGen.cs | 111 ++--- generator/Parameters.cs | 145 ++++++- generator/Signal.cs | 14 +- generator/SymbolTable.cs | 8 +- generator/gtkapi.xml | 4 +- glib/Boxed.cs | 3 + glib/IWrapper.cs | 15 + glib/Object.cs | 5 +- glue/textiter.c | 8 +- parser/Atk.metadata | 28 ++ parser/GAPI/Metadata.pm | 78 +++- parser/Gtk.metadata | 890 ++++++++++++++++++++++++++++++++++++++ parser/Metadata.pm | 78 +++- parser/gapi2xml.pl | 93 +++- parser/gapi_pp.pl | 10 +- sample/ButtonApp.cs | 2 +- sample/Menu.cs | 6 +- sources/Atk.metadata | 28 ++ sources/Gtk.metadata | 890 ++++++++++++++++++++++++++++++++++++++ 24 files changed, 2657 insertions(+), 288 deletions(-) create mode 100644 generator/ClassBase.cs create mode 100644 glib/IWrapper.cs create mode 100644 parser/Atk.metadata create mode 100644 sources/Atk.metadata diff --git a/ChangeLog b/ChangeLog index 148ec1b21..1119b10d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,51 @@ +2002-06-21 Rachel Hestilow + + * generator/ClassBase.cs: New base class for classes and interfaces. + + * generator/InterfaceGen.cs: Inherit from ClassBase, generate declarations. + + * generator/ObjectGen.cs: Move half of this into ClassBase. + + * generator/Method.cs: Turn all applicable Get/Set functions into .NET + accessors. Remove redundant == overload and move into Equals, as + it was confusing "!= null". + + * generator/Parameters.cs: Alter signature creation to accept "is_set" + option, add support for variable arguments. Add properties "Count", + "IsVarArgs", "VAType". + + * generator/Ctor.cs: Fixup for changes in Parameters (indenting, + signature creation). + + * generator/Signal.cs: Support generating declarations. + + * generator/SymbolTable: Change GetObjectGen to GetClassGen. + + * glib/IWrapper.cs: Move "Handle" declaration to here, so + both classes and interfaces can benefit from it. + + * glib/Object.cs: Inherit from IWrapper.cs + + * parser/Metadata.pm: Support attribute changes on constructors, + methods, signals, and paramater lists. + + * parser/gapi2xml.pl: Parse init funcs for interfaces. Ignore "_" + functions here. + + * parser/gapi_pp.pl: Remove boxed_type_register check, as it will + be caught in the init funcs. + + * parser/Atk.metadata: Added. + + * parser/Gtk.metadata: Add all needed signal/method collision + renames. Rename GtkEditable.Editable accessors to IsEditable, + as .NET does not like accessors with the same name as their + declaring type. Tag TreeStore constructor as varargs. + + * samples/ButtonApp.cs: s/EmitAdd/Add. + + * samples/Menu.cs: s/EmitAdd/Add, s/Activate/Activated. + 2002-06-21 Mike Kestner * */makefile.win32 : add /doc flags diff --git a/generator/ClassBase.cs b/generator/ClassBase.cs new file mode 100644 index 000000000..82d045f26 --- /dev/null +++ b/generator/ClassBase.cs @@ -0,0 +1,149 @@ +// GtkSharp.Generation.ClassBase.cs - Common code between object +// and interface wrappers +// +// Authors: Rachel Hestilow +// Mike Kestner +// +// (c) 2002 Rachel Hestilow, 2001-2002 Mike Kestner + +namespace GtkSharp.Generation { + using System; + using System.Collections; + using System.IO; + using System.Xml; + + public class ClassBase : GenBase { + protected Hashtable props = new Hashtable(); + protected Hashtable sigs = new Hashtable(); + protected Hashtable methods = new Hashtable(); + protected ArrayList interfaces = null; + + protected ClassBase (string ns, XmlElement elem) : base (ns, elem) { + foreach (XmlNode node in elem.ChildNodes) { + XmlElement member = (XmlElement) node; + + switch (node.Name) { + case "method": + methods.Add (member.GetAttribute ("name"), new Method (ns, member, this)); + break; + + case "property": + props.Add (member.GetAttribute ("name"), new Property (member)); + break; + + case "signal": + sigs.Add (member.GetAttribute ("name"), new Signal (ns, member)); + break; + + case "implements": + interfaces = ParseImplements (member); + break; + + default: + break; + } + } + } + + protected bool IsNodeNameHandled (string name) + { + switch (name) { + case "method": + case "property": + case "signal": + case "implements": + return true; + + default: + return false; + } + } + + public String MarshalType { + get + { + return "IntPtr"; + } + } + + public String CallByName (String var_name) + { + return var_name + ".Handle"; + } + + public String FromNative(String var) + { + return "(" + QualifiedName + ") GLib.Object.GetObject(" + var + ")"; + } + + protected void GenProperties (StreamWriter sw) + { + if (props == null) + return; + + foreach (Property prop in props.Values) { + if (prop.Validate ()) + prop.Generate (sw); + else + Console.WriteLine(" in Object " + Name); + } + } + + protected void GenSignals (StreamWriter sw) + { + if (sigs == null) + return; + + sw.WriteLine("\t\tprivate Hashtable Signals = new Hashtable();"); + + foreach (Signal sig in sigs.Values) { + if (sig.Validate ()) + sig.Generate (sw); + else + Console.WriteLine(" in Object " + Name); + } + } + + private ArrayList ParseImplements (XmlElement member) + { + ArrayList ifaces = new ArrayList (); + + foreach (XmlNode node in member.ChildNodes) { + if (node.Name != "interface") + continue; + XmlElement element = (XmlElement) node; + ifaces.Add (element.GetAttribute ("cname")); + } + + return ifaces; + } + + protected bool IgnoreMethod (Method method) + { + string mname = method.Name; + return ((mname.StartsWith("Set") || mname.StartsWith("Get")) && + (props != null) && props.ContainsKey(mname.Substring(3))); + } + + protected void GenMethods (StreamWriter sw) + { + if (methods == null) + return; + + foreach (Method method in methods.Values) { + if (IgnoreMethod (method)) + continue; + + if (method.Validate ()) + method.Generate (sw); + else + Console.WriteLine(" in Object " + Name); + } + } + + public Method GetMethod (string name) + { + return (Method) methods[name]; + } + } +} diff --git a/generator/Ctor.cs b/generator/Ctor.cs index 20ed5413f..cd0e7778d 100644 --- a/generator/Ctor.cs +++ b/generator/Ctor.cs @@ -27,10 +27,13 @@ namespace GtkSharp.Generation { public bool Validate () { - if ((parms != null) && !parms.Validate ()) { - Console.Write("ctor "); - Statistics.ThrottledCount++; - return false; + if (parms != null) { + if (!parms.Validate ()) { + Console.Write("ctor "); + Statistics.ThrottledCount++; + return false; + } + parms.CreateSignature (false); } return true; @@ -79,19 +82,19 @@ namespace GtkSharp.Generation { sw.WriteLine("\t\tpublic static " + safety + name + " " + mname + sig); sw.WriteLine("\t\t{"); if (parms != null) - parms.Initialize(sw, false); + parms.Initialize(sw, false, ""); sw.WriteLine("\t\t\tIntPtr ret = " + cname + call + ";"); if (parms != null) - parms.HandleException (sw); + parms.HandleException (sw, ""); sw.WriteLine("\t\t\treturn new " + name + "(ret);"); } else { sw.WriteLine("\t\tpublic " + safety + name + sig); sw.WriteLine("\t\t{"); if (parms != null) - parms.Initialize(sw, false); + parms.Initialize(sw, false, ""); sw.WriteLine("\t\t\tRaw = " + cname + call + ";"); if (parms != null) - parms.HandleException (sw); + parms.HandleException (sw, ""); } sw.WriteLine("\t\t}"); diff --git a/generator/InterfaceGen.cs b/generator/InterfaceGen.cs index 1b6997fd0..58ad9fe1a 100644 --- a/generator/InterfaceGen.cs +++ b/generator/InterfaceGen.cs @@ -10,27 +10,10 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public class InterfaceGen : GenBase, IGeneratable { + public class InterfaceGen : ClassBase, IGeneratable { public InterfaceGen (string ns, XmlElement elem) : base (ns, elem) {} - public String MarshalType { - get - { - return ""; - } - } - - public String CallByName (String var_name) - { - return ""; - } - - public String FromNative(String var) - { - return ""; - } - public void Generate () { StreamWriter sw = CreateWriter (); @@ -38,22 +21,26 @@ namespace GtkSharp.Generation { sw.WriteLine ("\tusing System;"); sw.WriteLine (); - sw.WriteLine ("\tpublic interface " + Name + " {"); + sw.WriteLine ("\tpublic interface " + Name + " : GLib.IWrapper {"); sw.WriteLine (); + + foreach (Signal sig in sigs.Values) { + if (sig.Validate ()) + sig.GenerateDecl (sw); + } - foreach (XmlNode node in Elem.ChildNodes) { - if (node.Name != "member") { + foreach (Method method in methods.Values) { + if (IgnoreMethod (method)) continue; - } - //FIXME: Generate the methods. - XmlElement member = (XmlElement) node; + + if (method.Validate ()) + method.GenerateDecl (sw); } sw.WriteLine ("\t}"); CloseWriter (sw); Statistics.IFaceCount++; } - } } diff --git a/generator/Method.cs b/generator/Method.cs index eafa89048..c661c0f99 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -16,21 +16,30 @@ namespace GtkSharp.Generation { private string ns; private XmlElement elem; private Parameters parms; - - public Method (string ns, XmlElement elem) + private ClassBase container_type; + + private bool initialized = false; + private string sig, isig, call; + private string rettype, m_ret, s_ret; + private string name, cname, safety; + private bool is_get, is_set; + + public Method (string ns, XmlElement elem, ClassBase container_type) { this.ns = ns; this.elem = elem; if (elem["parameters"] != null) parms = new Parameters (elem["parameters"]); + this.container_type = container_type; + this.name = elem.GetAttribute("name"); } public string Name { get { - return elem.GetAttribute("name"); + return name; } set { - elem.SetAttribute("name", value); + name = value; } } @@ -44,12 +53,17 @@ namespace GtkSharp.Generation { { if (!(o is Method)) return false; - +/* return (this == (Method) o); } public static bool operator == (Method a, Method b) { + if (a == null) + return (b +*/ + Method a = this; + Method b = (Method) o; if (a.Name != b.Name) return false; @@ -61,9 +75,10 @@ namespace GtkSharp.Generation { return (a.Params.SignatureTypes == b.Params.SignatureTypes); } - +/* public static bool operator != (Method a, Method b) { + return !( if (a.Name == b.Name) return false; @@ -75,36 +90,37 @@ namespace GtkSharp.Generation { return (a.Params.SignatureTypes != b.Params.SignatureTypes); } - - public bool Validate () +*/ + private bool Initialize () { + if (initialized) + return true; + + if (parms != null && !parms.Validate ()) + return false; + XmlElement ret_elem = elem["return-type"]; if (ret_elem == null) { Console.Write("Missing return type in method "); Statistics.ThrottledCount++; return false; } + + rettype = ret_elem.GetAttribute("type"); + m_ret = SymbolTable.GetMarshalType(rettype); + s_ret = SymbolTable.GetCSType(rettype); + cname = elem.GetAttribute("cname"); - 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; - } + if (parms != null && parms.ThrowsException) + safety = "unsafe "; + else + safety = ""; - if (Params == null) - return true; - - return Params.Validate (); - } - - public void Generate (StreamWriter sw) - { - string sig, isig, call; + is_get = ((parms != null && (parms.IsAccessor || (parms.Count == 0 && s_ret != "void")) || (parms == null && s_ret != "void")) && Name.Substring(0, 3) == "Get"); + is_set = ((parms != null && (parms.IsAccessor || (parms.Count == 1 && s_ret == "void"))) && (Name.Substring(0, 3) == "Set")); if (parms != null) { + parms.CreateSignature (is_set); sig = "(" + parms.Signature + ")"; isig = "(IntPtr raw, " + parms.ImportSig + ");"; call = "(Handle, " + parms.CallString + ")"; @@ -114,70 +130,188 @@ namespace GtkSharp.Generation { call = "(Handle)"; } - string rettype = elem["return-type"].GetAttribute("type"); - string m_ret = SymbolTable.GetMarshalType(rettype); - string s_ret = SymbolTable.GetCSType(rettype); - string cname = elem.GetAttribute("cname"); + initialized = true; + return true; + } + + public bool Validate () + { + if (!Initialize ()) + return false; - if (cname[0] == '_') { + if (m_ret == "" || s_ret == "") { + Console.Write("rettype: " + rettype + " method "); Statistics.ThrottledCount++; - return; + return false; } - - string safety; - if (parms != null && parms.ThrowsException) - safety = "unsafe "; + return true; + } + + private Method GetComplement () + { + char complement; + if (is_get) + complement = 'S'; else - safety = ""; + complement = 'G'; + + return container_type.GetMethod (complement + elem.GetAttribute("name").Substring (1)); + } + + private void GenerateDeclCommon (StreamWriter sw) + { + sw.Write(safety); + if (is_get || is_set) { + if (s_ret == "void") + s_ret = parms.AccessorReturnType; + sw.Write(s_ret); + sw.Write(" "); + sw.Write(Name.Substring (3)); + sw.WriteLine(" { "); + } else { + if (elem.HasAttribute("new_flag")) + sw.Write("new "); + sw.Write(s_ret + " " + Name + sig); + } + } - sw.WriteLine("\t\t/// " + Name + " Method "); - sw.WriteLine("\t\t/// To be completed "); - sw.WriteLine(); + public void GenerateDecl (StreamWriter sw) + { + if (!Initialize ()) + return; + + if (is_get || is_set) + { + Method comp = GetComplement (); + if (comp != null && comp.Validate () && is_set) + return; + + sw.Write("\t\t"); + GenerateDeclCommon (sw); + + sw.Write("\t\t\t"); + sw.Write ((is_get) ? "get;" : "set;"); + + if (comp != null && comp.is_set) + sw.WriteLine (" set;"); + else + sw.WriteLine (); + + sw.WriteLine ("\t\t}"); + } + else + { + sw.Write("\t\t"); + GenerateDeclCommon (sw); + sw.WriteLine (";"); + } + + Statistics.MethodCount++; + } + + protected void GenerateImport (StreamWriter sw) + { sw.WriteLine("\t\t[DllImport(\"" + SymbolTable.GetDllName(ns) + "\", CallingConvention=CallingConvention.Cdecl)]"); sw.Write("\t\tstatic extern " + safety + m_ret + " " + cname + isig); sw.WriteLine(); + } - sw.Write("\t\tpublic " + safety); - bool is_get = (parms != null && parms.IsAccessor && Name.Substring(0, 3) == "Get"); - if (is_get) { - s_ret = parms.AccessorReturnType; - sw.Write(s_ret); - sw.Write(" "); - sw.Write(Name.Substring (3)); - sw.Write(" { get"); - } else { - if (elem.HasAttribute("new_flag")) - sw.Write("new "); - sw.WriteLine(s_ret + " " + Name + sig); + public void Generate (StreamWriter sw) + { + Method comp = null; + + if (!Initialize ()) + return; + + /* we are generated by the get Method, if there is one */ + if (is_set || is_get) + { + comp = GetComplement (); + if (comp != null && comp.Validate () && is_set && parms.AccessorReturnType == comp.s_ret) + return; + if (comp != null && is_set && parms.AccessorReturnType != comp.s_ret) + { + is_set = false; + parms.CreateSignature (false); + call = "(Handle, " + parms.CallString + ")"; + comp = null; + } + /* some setters take more than one arg */ + if (comp != null && !comp.is_set) + comp = null; } - sw.WriteLine("\t\t{"); - if (parms != null) - parms.Initialize(sw, is_get); - sw.Write("\t\t\t"); - if (is_get || m_ret == "void") { - sw.WriteLine(cname + call + ";"); - } else { - sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNative(rettype, cname + call) + ";"); + else { + sw.WriteLine("\t\t/// " + Name + " Method "); + sw.WriteLine("\t\t/// To be completed "); + sw.WriteLine(); } - - if (parms != null) - parms.HandleException (sw); - if (is_get) - sw.WriteLine ("\t\t\treturn " + parms.AccessorName + ";"); - else if (m_ret != "void") - sw.WriteLine ("\t\t\treturn ret;"); - - sw.Write("\t\t}"); - if (is_get) - sw.Write(" }"); + GenerateImport (sw); + if (comp != null && s_ret == comp.parms.AccessorReturnType) + comp.GenerateImport (sw); + + sw.Write("\t\tpublic "); + GenerateDeclCommon (sw); + + if (is_get || is_set) + { + sw.Write ("\t\t\t"); + sw.Write ((is_get) ? "get" : "set"); + GenerateBody (sw, "\t"); + } + else + GenerateBody (sw, ""); + + if (is_get || is_set) + { + if (comp != null && s_ret == comp.parms.AccessorReturnType) + { + sw.WriteLine (); + sw.Write ("\t\t\tset"); + comp.GenerateBody (sw, "\t"); + } + sw.WriteLine (); + sw.WriteLine ("\t\t}"); + } + else + sw.WriteLine(); - sw.WriteLine(); sw.WriteLine(); Statistics.MethodCount++; } + + protected void GenerateBody (StreamWriter sw, string indent) + { + sw.WriteLine(" {"); + if (parms != null) + parms.Initialize(sw, is_get, indent); + + sw.Write(indent + "\t\t\t"); + if (m_ret == "void") { + sw.WriteLine(cname + call + ";"); + } else { + if (SymbolTable.IsObject (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\tif (ret == null) ret = new " + s_ret + "(raw_ret);"); + } + else + sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNative(rettype, cname + call) + ";"); + } + + if (parms != null) + parms.HandleException (sw, indent); + + if (is_get && parms != null) + sw.WriteLine (indent + "\t\t\treturn " + parms.AccessorName + ";"); + else if (m_ret != "void") + sw.WriteLine (indent + "\t\t\treturn ret;"); + + sw.Write(indent + "\t\t}"); + } } } diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index 65b043af0..56cbae803 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -11,12 +11,9 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public class ObjectGen : GenBase, IGeneratable { + public class ObjectGen : ClassBase, IGeneratable { private ArrayList ctors = new ArrayList(); - private Hashtable props = new Hashtable(); - private Hashtable sigs = new Hashtable(); - private Hashtable methods = new Hashtable(); public ObjectGen (string ns, XmlElement elem) : base (ns, elem) { @@ -33,46 +30,19 @@ namespace GtkSharp.Generation { case "constructor": ctors.Add (new Ctor (ns, member)); break; - - case "method": - methods.Add (member.GetAttribute ("name"), new Method (ns, member)); - break; - - case "property": - props.Add (member.GetAttribute ("name"), new Property (member)); - break; - - case "signal": - sigs.Add (member.GetAttribute ("name"), new Signal (ns, member)); - break; - + default: - Console.WriteLine ("Unexpected node " + node.Name + " in " + CName); + if (!IsNodeNameHandled (node.Name)) + Console.WriteLine ("Unexpected node " + node.Name + " in " + CName); break; } } } - public string MarshalType { - get { - return "IntPtr"; - } - } - - public string CallByName (string var_name) - { - return var_name + ".Handle"; - } - - public string FromNative(string var) - { - return "(" + QualifiedName + ") GLib.Object.GetObject(" + var + ")"; - } - private ObjectGen Parent { get { string parent = Elem.GetAttribute("parent"); - return SymbolTable.GetObjectGen(parent); + return (ObjectGen) SymbolTable.GetClassGen(parent); } } @@ -89,6 +59,11 @@ namespace GtkSharp.Generation { string cs_parent = SymbolTable.GetCSType(Elem.GetAttribute("parent")); if (cs_parent != "") sw.Write (" : " + cs_parent); + if (interfaces != null) { + foreach (string iface in interfaces) { + sw.Write (", " + SymbolTable.GetCSType (iface)); + } + } sw.WriteLine (" {"); sw.WriteLine (); @@ -96,6 +71,14 @@ namespace GtkSharp.Generation { GenProperties (sw); GenSignals (sw); GenMethods (sw); + + if (interfaces != null) { + foreach (string iface in interfaces) { + ClassBase igen = SymbolTable.GetClassGen (iface); + igen.GenMethods (sw); + } + } + AppendCustom(Namespace, Name, sw); sw.WriteLine ("\t}"); @@ -103,7 +86,7 @@ namespace GtkSharp.Generation { CloseWriter (sw); Statistics.ObjectCount++; } - + private bool Validate () { string parent = Elem.GetAttribute("parent"); @@ -133,6 +116,13 @@ namespace GtkSharp.Generation { if (!method.Validate()) return false; + if (interfaces != null) { + foreach (string iface in interfaces) { + if (SymbolTable.GetCSType(parent) == null) + return false; + } + } + return true; } @@ -157,55 +147,6 @@ namespace GtkSharp.Generation { } } - - private void GenProperties (StreamWriter sw) - { - if (props == null) - return; - - foreach (Property prop in props.Values) { - if (prop.Validate ()) - prop.Generate (sw); - else - Console.WriteLine(" in Object " + Name); - } - } - - private void GenSignals (StreamWriter sw) - { - if (sigs == null) - return; - - sw.WriteLine("\t\tprivate Hashtable Signals = new Hashtable();"); - - foreach (Signal sig in sigs.Values) { - if (sig.Validate ()) - sig.Generate (sw); - else - Console.WriteLine(" in Object " + Name); - } - } - - private void GenMethods (StreamWriter sw) - { - if (methods == null) - return; - - foreach (Method method in methods.Values) { - string mname = method.Name; - if ((mname.StartsWith("Set") || mname.StartsWith("Get")) && - (props != null) && props.ContainsKey(mname.Substring(3))) { - continue; - } else if ((sigs != null) && sigs.ContainsKey(mname)) { - method.Name = "Emit" + mname; - } - - if (method.Validate ()) - method.Generate (sw); - else - Console.WriteLine(" in Object " + Name); - } - } } } diff --git a/generator/Parameters.cs b/generator/Parameters.cs index 08ad1d330..d6c555121 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -49,9 +49,6 @@ namespace GtkSharp.Generation { public bool Validate () { - signature_types = signature = import_sig = call_string = ""; - bool need_sep = false; - foreach (XmlNode parm in elem.ChildNodes) { if (parm.Name != "parameter") { continue; @@ -69,16 +66,58 @@ namespace GtkSharp.Generation { Console.Write("Name: " + name + " Type: " + type + " "); return false; } + } + + return true; + } + public void CreateSignature (bool is_set) + { + signature_types = signature = import_sig = call_string = ""; + bool need_sep = false; + + int len = 0; + XmlElement last_param; + foreach (XmlNode parm in elem.ChildNodes) { + if (parm.Name != "parameter") { + continue; + } + len++; + last_param = (XmlElement) parm; + } + + int i = 0; + foreach (XmlNode parm in elem.ChildNodes) { + if (parm.Name != "parameter") { + continue; + } + + XmlElement p_elem = (XmlElement) parm; + string type = p_elem.GetAttribute("type"); + string cs_type = SymbolTable.GetCSType(type); + string m_type = SymbolTable.GetMarshalType(type); + string name = MangleName(p_elem.GetAttribute("name")); + string call_parm; + + if (is_set && i == 0) + call_parm = SymbolTable.CallByName(type, "value"); + else + call_parm = SymbolTable.CallByName(type, name); + if (p_elem.HasAttribute("array")) { cs_type += "[]"; m_type += "[]"; } + + if (IsVarArgs && i == (len - 1) && VAType == "length_param") { + cs_type = "params " + cs_type + "[]"; + m_type += "[]"; + } if (need_sep) { call_string += ", "; import_sig += ", "; - if (type != "GError**") + if (type != "GError**" && !(IsVarArgs && i == (len - 1) && VAType == "length_param")) { signature += ", "; signature_types += ":"; @@ -88,24 +127,40 @@ namespace GtkSharp.Generation { } if (p_elem.HasAttribute("pass_as")) { - signature += p_elem.GetAttribute("pass_as") + " "; + string pass_as = p_elem.GetAttribute("pass_as"); + signature += pass_as + " "; + // We only need to do this for value types + if (type != "GError**" && m_type != "IntPtr" && m_type != "System.IntPtr") + { + import_sig += pass_as + " "; + call_string += "out "; + } } - - if (type == "GError**") { + else if (type == "GError**") + { call_string += "out "; import_sig += "out "; - } else { - signature += (cs_type + " " + name); - signature_types += cs_type; } - call_string += call_parm; + + if (IsVarArgs && i == (len - 2) && VAType == "length_param") + { + call_string += MangleName(last_param.GetAttribute("name")) + ".Length"; + } + else + { + if (type != "GError**") { + signature += (cs_type + " " + name); + signature_types += cs_type; + } + call_string += call_parm; + } import_sig += (m_type + " " + name); + + i++; } - - return true; } - public void Initialize (StreamWriter sw, bool is_get) + public void Initialize (StreamWriter sw, bool is_get, string indent) { string name = ""; foreach (XmlNode parm in elem.ChildNodes) { @@ -115,28 +170,64 @@ namespace GtkSharp.Generation { XmlElement p_elem = (XmlElement) parm; - string type = SymbolTable.GetCSType(p_elem.GetAttribute ("type")); + string c_type = p_elem.GetAttribute ("type"); + string type = SymbolTable.GetCSType(c_type); name = MangleName(p_elem.GetAttribute("name")); if (is_get) { - sw.WriteLine ("\t\t\t" + type + " " + name + ";"); + sw.WriteLine (indent + "\t\t\t" + type + " " + name + ";"); } - if (is_get || (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out")) { - sw.WriteLine("\t\t\t" + name + " = new " + type + "();"); + if ((is_get || (p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out")) && (SymbolTable.IsObject (c_type) || SymbolTable.IsBoxed (c_type))) { + sw.WriteLine(indent + "\t\t\t" + name + " = new " + type + "();"); } } if (ThrowsException) - sw.WriteLine ("\t\t\tIntPtr error;"); + sw.WriteLine (indent + "\t\t\tIntPtr error;"); } +/* + public void Finish (StreamWriter sw) + { + foreach (XmlNode parm in elem.ChildNodes) { + if (parm.Name != "parameter") { + continue; + } + + XmlElement p_elem = (XmlElement) parm; + string c_type = p_elem.GetAttribute ("type"); + string name = MangleName(p_elem.GetAttribute("name")); - public void HandleException (StreamWriter sw) + if ((p_elem.HasAttribute("pass_as") && p_elem.GetAttribute ("pass_as") == "out")) { + string call_parm = SymbolTable.CallByName(c_type, name); + string local_parm = GetPossibleLocal (call_parm); + if (call_parm != local_parm) + sw.WriteLine ("\t\t\t{0} = {1};", call_parm, local_parm); + } + } + } +*/ + + public void HandleException (StreamWriter sw, string indent) { if (!ThrowsException) return; - sw.WriteLine ("\t\t\tif (error != IntPtr.Zero) throw new GLib.GException (error);"); + sw.WriteLine (indent + "\t\t\tif (error != IntPtr.Zero) throw new GLib.GException (error);"); } + public int Count { + get { + int length = 0; + foreach (XmlNode parm in elem.ChildNodes) { + if (parm.Name != "parameter") { + continue; + } + + length++; + } + return length; + } + } + public bool IsAccessor { get { int length = 0; @@ -169,6 +260,18 @@ namespace GtkSharp.Generation { } } + public bool IsVarArgs { + get { + return elem.HasAttribute ("va_type"); + } + } + + public string VAType { + get { + return elem.GetAttribute ("va_type"); + } + } + public string AccessorReturnType { get { foreach (XmlNode parm in elem.ChildNodes) { diff --git a/generator/Signal.cs b/generator/Signal.cs index a72fc4183..ce8dab9f4 100644 --- a/generator/Signal.cs +++ b/generator/Signal.cs @@ -15,17 +15,22 @@ namespace GtkSharp.Generation { private string ns; private string marsh; + private string name; private XmlElement elem; public Signal (string ns, XmlElement elem) { this.ns = ns; this.elem = elem; + this.name = elem.GetAttribute ("name"); } public string Name { get { - return elem.GetAttribute ("name"); + return name; + } + set { + name = value; } } @@ -41,6 +46,13 @@ namespace GtkSharp.Generation { return true; } + public void GenerateDecl (StreamWriter sw) + { + if (elem.HasAttribute("new_flag")) + sw.Write("new "); + sw.WriteLine ("\t\tevent EventHandler " + Name + ";"); + } + public void Generate (StreamWriter sw) { string cname = "\"" + elem.GetAttribute("cname") + "\""; diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index a8723f4b9..25d960a61 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -234,16 +234,16 @@ namespace GtkSharp.Generation { return false; } - public static ObjectGen GetObjectGen(string c_type) + public static ClassBase GetClassGen(string c_type) { c_type = Trim(c_type); c_type = DeAlias(c_type); - if (IsObject(c_type)) { - return (ObjectGen) complex_types[c_type]; + if (IsInterface(c_type) || IsObject (c_type)) { + return (ClassBase) complex_types[c_type]; } return null; } - + public static bool IsObject(string c_type) { c_type = Trim(c_type); diff --git a/generator/gtkapi.xml b/generator/gtkapi.xml index bb443b61c..b32d1b769 100644 --- a/generator/gtkapi.xml +++ b/generator/gtkapi.xml @@ -1,2 +1,2 @@ - - + + diff --git a/glib/Boxed.cs b/glib/Boxed.cs index 9eb31b3d2..bb854bb62 100644 --- a/glib/Boxed.cs +++ b/glib/Boxed.cs @@ -47,6 +47,9 @@ namespace GLib { get { return raw; } + set { + raw = value; + } } /// diff --git a/glib/IWrapper.cs b/glib/IWrapper.cs new file mode 100644 index 000000000..c1feb6e2c --- /dev/null +++ b/glib/IWrapper.cs @@ -0,0 +1,15 @@ +// IWrapper.cs - Common code for GInterfaces and GObjects +// +// Author: Rachel Hestilow +// +// (c) 2002 Rachel Hestilow + +namespace GLib +{ + using System; + + public interface IWrapper + { + IntPtr Handle { get; set; } + } +} diff --git a/glib/Object.cs b/glib/Object.cs index ce9b6bd36..40d3b7413 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -20,7 +20,7 @@ namespace GLib { /// Wrapper class for GObject. /// - public class Object { + public class Object : IWrapper { // Private class and instance members IntPtr _obj; @@ -109,6 +109,9 @@ namespace GLib { get { return _obj; } + set { + _obj = value; + } } /// diff --git a/glue/textiter.c b/glue/textiter.c index 22c880afe..5b44cba0d 100644 --- a/glue/textiter.c +++ b/glue/textiter.c @@ -14,4 +14,10 @@ gtksharp_text_iter_create (void) 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/parser/Atk.metadata b/parser/Atk.metadata new file mode 100644 index 000000000..bb1f17e50 --- /dev/null +++ b/parser/Atk.metadata @@ -0,0 +1,28 @@ + + + + + + + GetDocument + + + + name + GetTheDocument + + + + + + SetDocument + + + + name + SetTheDocument + + + + + diff --git a/parser/GAPI/Metadata.pm b/parser/GAPI/Metadata.pm index e00f7c58f..8e2bcd418 100644 --- a/parser/GAPI/Metadata.pm +++ b/parser/GAPI/Metadata.pm @@ -24,13 +24,17 @@ sub new { sub parseClass { my ($node, $classes) = @_; my %methods = (); + my %signals = (); my @attrs = $node->attributes; my $class_name = $attrs[0]->value; - ${$classes}{$class_name} = \%methods; + ${$classes}{$class_name} = [\%methods, \%signals]; for ($method_node = $node->firstChild; $method_node != undef; $method_node = $method_node->nextSibling ()) { - next if $method_node->nodeName ne "method"; - $methods{$method_node->firstChild->nodeValue} = 1; + if ($method_node->nodeName eq "method" or $method_node->nodeName eq "constructor") { + $methods{$method_node->firstChild->nodeValue} = 1; + } elsif ($method_node->nodeName eq "signal") { + $signals{$method_node->firstChild->nodeValue} = 1; + } } } @@ -84,23 +88,35 @@ sub load { sub fixupParams { my ($method_node, $data_list_ref) = @_; my ($params_node, $node); - for ($node = $method_node->firstChild; $node; $node = $node->nextSibling ()) { - if ($node->nodeName eq "parameters") { - $params_node = $node; - last; + + foreach $data (@$data_list_ref) { + if ($$data[1] eq "method" or $$data[1] eq "signal") { + $method_node->setAttribute ($$data[5], $$data[6]); + next; } - } - return if not $params_node; - for ($node = $params_node->firstChild; $node; $node = $node->nextSibling ()) { - my $param_type; - foreach $attr ($node->attributes) { - if ($attr->name eq "type") { - $param_type = $attr->value; + + for ($node = $method_node->firstChild; $node; $node = $node->nextSibling ()) { + if ($node->nodeName eq "parameters") { + $params_node = $node; last; } } + next if not $params_node; + if ($$data[1] eq "parameters") { + $params_node->setAttribute ($$data[5], $$data[6]); + next; + } - foreach $data (@$data_list_ref) { + + for ($node = $params_node->firstChild; $node; $node = $node->nextSibling ()) { + my $param_type; + foreach $attr ($node->attributes) { + if ($attr->name eq "type") { + $param_type = $attr->value; + last; + } + } + if ($param_type eq $$data[4]) { $node->setAttribute ($$data[5], $$data[6]); } @@ -114,7 +130,7 @@ sub fixupNamespace { foreach $rule (@{$self->{rules}}) { my ($classes_ref, $data_list_ref) = @$rule; for ($node = $ns_node->firstChild; $node; $node = $node->nextSibling ()) { - next if $node->nodeName ne "object"; + next if not ($node->nodeName eq "object" or $node->nodeName eq "interface"); my $class, $methods_ref, $attr; foreach $attr ($node->attributes) { if ($attr->name eq "cname") { @@ -124,21 +140,38 @@ sub fixupNamespace { } my %classes = %$classes_ref; - $methods_ref = $classes{$class}; - next if not $methods_ref; + $methods_ref = $classes{$class}[0]; + $signals_ref = $classes{$class}[1]; + next if not ($methods_ref or $signals_ref); for ($method_node = $node->firstChild; $method_node; $method_node = $method_node->nextSibling ()) { - next if $method_node->nodeName ne "method"; + next if not ($method_node->nodeName eq "method" or $method_node->nodeName eq "constructor"); my $method; foreach $attr ($method_node->attributes) { - if ($attr->name eq "name") { + if (($attr->name eq "name" and $method_node->nodeName eq "method") or ($attr->name eq "cname" and $method_node->nodeName eq "constructor")) { $method = $attr->value; last; } } - next if not ${$methods_ref}{$method}; + next if not ${%$methods_ref}{$method}; + fixupParams ($method_node, $data_list_ref); } + + for ($signal_node = $node->firstChild; $signal_node; $signal_node = $signal_node->nextSibling ()) { + next if $signal_node->nodeName ne "signal"; + my $signal; + foreach $attr ($signal_node->attributes) { + if ($attr->name eq "name") { + $signal = $attr->value; + last; + } + } + next if not ${$signals_ref}{$signal}; + + fixupParams ($signal_node, $data_list_ref); + } + } } } @@ -152,8 +185,9 @@ sub fixup { return if not ($api_node and $api_node->nodeName eq "api"); for ($ns_node = $api_node->firstChild; $ns_node; $ns_node = $ns_node->nextSibling ()) { next if $ns_node->nodeName ne "namespace"; - next if not ($ns_node->attributes and (scalar (@{$ns_node->attributes})) + 1); + next if not $ns_node->attributes; my @attrs = $ns_node->attributes; + next if not @attrs; my $namespace = $attrs[0]->value; if (-f "$namespace.metadata") { if (not ($metadata and $metadata->{namespace} eq $namespace)) { diff --git a/parser/Gtk.metadata b/parser/Gtk.metadata index f80180b68..1ef7b2467 100644 --- a/parser/Gtk.metadata +++ b/parser/Gtk.metadata @@ -1,5 +1,7 @@ + + GetIterAtLineOffset @@ -28,4 +30,892 @@ + + + InsertText + + + + gint* + pass_as + out + + + + + + + + gtk_tree_store_newv + + + + va_type + length_param + + + + + + + + GetEditable + + + + name + GetIsEditable + + + + + + SetEditable + + + + name + SetIsEditable + + + + + + Add + + + + name + Added + + + + + + Remove + + + + name + Removed + + + + + + InsertText + + + + name + TextInserted + + + + + + DeleteText + + + + name + TextDeleted + + + + + + Show + + + + name + Shown + + + + + + Hide + + + + name + Hidden + + + + + + Map + + + + name + Mapped + + + + + + Unmap + + + + name + Unmapped + + + + + + Realize + + + + name + Realized + + + + + + Unrealize + + + + name + Unrealized + + + + + + GrabFocus + + + + name + FocusGrabbed + + + + + + SizeAllocate + + + + name + SizeAllocated + + + + + + MnemonicActivate + + + + name + MnemonicActivated + + + + + + SizeRequest + + + + name + SizeRequested + + + + + + ChildNotify + + + + name + ChildNotified + + + + + + + InsertPixbuf + + + + name + PixbufInserted + + + + + + ApplyTag + + + + name + TagApplied + + + + + + RemoveTag + + + + name + TagRemoved + + + + + + InsertChildAnchor + + + + name + ChildAnchorInserted + + + + + + RemoveChildAnchor + + + + name + ChildAnchorRemoved + + + + + + Select + + + + name + Selected + + + + + + Deselect + + + + name + Deselected + + + + + + Toggle + + + + name + Toggled + + + + + + SelectChild + + + + name + ChildSelected + + + + + + UnselectChild + + + + name + ChildUnselected + + + + + + SelectChild + + + + name + ChildSelected + + + + + + UnselectChild + + + + name + ChildUnselected + + + + + + + StartQuery + + + + name + QueryStarted + + + + + + StopQuery + + + + name + QueryStopped + + + + + + Collapse + + + + name + Collapsed + + + + + + Expand + + + + name + Expanded + + + + + + SetFocusChild + + + + name + FocusChildSet + + + + + + PasteClipboard + + + + name + ClipboardPasted + + + + + + CutClipboard + + + + name + ClipboardCut + + + + + + CopyClipboard + + + + name + ClipboardCopied + + + + + + PasteClipboard + + + + name + ClipboardPasted + + + + + + CutClipboard + + + + name + ClipboardCut + + + + + + CopyClipboard + + + + name + ClipboardCopied + + + + + + Activate + + + + name + Activated + + + + + + Deactivate + + + + name + Deactivated + + + + + + Deactivate + + + + name + Deactivated + + + + + + ToggleSizeRequest + + + + name + ToggleSizeRequested + + + + + + ToggleSizeAllocate + + + + name + ToggleSizeAllocated + + + + + + RemoveWidget + + + + name + WidgetRemoved + + + + + + SizeAllocate + + + + name + SizeAllocated + + + + + + MnemonicActivate + + + + name + MnemonicActivated + + + + + + SizeRequest + + + + name + SizeRequested + + + + + + ChildNotify + + + + name + ChildNotified + + + + + + Toggled + + + + name + Toggle + + + + + + Pressed + + + + name + Press + + + + + + Clicked + + + + name + Click + + + + + + Released + + + + name + Release + + + + + + Enter + + + + name + Entered + + + + + + Leave + + + + name + Left + + + + + + Deactivate + + + + name + Deactivated + + + + + + RemoveWidget + + + + name + WidgetRemoved + + + + + + EditingDone + + + + name + FinishEditing + + + + + + ActivateDefault + + + + name + DefaultActivated + + + + + + ActivateFocus + + + + name + FocusActivated + + + + + + Changed + + + + name + Change + + + + + + ValueChanged + + + + name + ChangeValue + + + + + + Destroy + + + + name + Destroyed + + + + + + RowActivated + + + + name + ActivateRow + + + + + + RowExpanded + + + + name + RowExpand + + + + + + RowDeleted + + + + name + DeleteRow + + + + + + RowHasChildToggled + + + + name + ToggleRowHasChild + + + + + + RowInserted + + + + name + InsertRow + + + + + + RowChanged + + + + name + ChangeRow + + + + + + RowsReordered + + + + name + ReorderRows + + + + + + SortColumnChanged + + + + name + ChangeSortColumn + + + + + + Response + + + + name + Respond + + + + + + EndUserAction + + + + name + UserActionEnded + + + + + + BeginUserAction + + + + name + UserActionBegun + + + + + + Toggled + + + + name + Toggle + + + + + + CheckResize + + + + name + ResizeChecked + + + + + + Clicked + + + + name + Click + + + + diff --git a/parser/Metadata.pm b/parser/Metadata.pm index e00f7c58f..8e2bcd418 100644 --- a/parser/Metadata.pm +++ b/parser/Metadata.pm @@ -24,13 +24,17 @@ sub new { sub parseClass { my ($node, $classes) = @_; my %methods = (); + my %signals = (); my @attrs = $node->attributes; my $class_name = $attrs[0]->value; - ${$classes}{$class_name} = \%methods; + ${$classes}{$class_name} = [\%methods, \%signals]; for ($method_node = $node->firstChild; $method_node != undef; $method_node = $method_node->nextSibling ()) { - next if $method_node->nodeName ne "method"; - $methods{$method_node->firstChild->nodeValue} = 1; + if ($method_node->nodeName eq "method" or $method_node->nodeName eq "constructor") { + $methods{$method_node->firstChild->nodeValue} = 1; + } elsif ($method_node->nodeName eq "signal") { + $signals{$method_node->firstChild->nodeValue} = 1; + } } } @@ -84,23 +88,35 @@ sub load { sub fixupParams { my ($method_node, $data_list_ref) = @_; my ($params_node, $node); - for ($node = $method_node->firstChild; $node; $node = $node->nextSibling ()) { - if ($node->nodeName eq "parameters") { - $params_node = $node; - last; + + foreach $data (@$data_list_ref) { + if ($$data[1] eq "method" or $$data[1] eq "signal") { + $method_node->setAttribute ($$data[5], $$data[6]); + next; } - } - return if not $params_node; - for ($node = $params_node->firstChild; $node; $node = $node->nextSibling ()) { - my $param_type; - foreach $attr ($node->attributes) { - if ($attr->name eq "type") { - $param_type = $attr->value; + + for ($node = $method_node->firstChild; $node; $node = $node->nextSibling ()) { + if ($node->nodeName eq "parameters") { + $params_node = $node; last; } } + next if not $params_node; + if ($$data[1] eq "parameters") { + $params_node->setAttribute ($$data[5], $$data[6]); + next; + } - foreach $data (@$data_list_ref) { + + for ($node = $params_node->firstChild; $node; $node = $node->nextSibling ()) { + my $param_type; + foreach $attr ($node->attributes) { + if ($attr->name eq "type") { + $param_type = $attr->value; + last; + } + } + if ($param_type eq $$data[4]) { $node->setAttribute ($$data[5], $$data[6]); } @@ -114,7 +130,7 @@ sub fixupNamespace { foreach $rule (@{$self->{rules}}) { my ($classes_ref, $data_list_ref) = @$rule; for ($node = $ns_node->firstChild; $node; $node = $node->nextSibling ()) { - next if $node->nodeName ne "object"; + next if not ($node->nodeName eq "object" or $node->nodeName eq "interface"); my $class, $methods_ref, $attr; foreach $attr ($node->attributes) { if ($attr->name eq "cname") { @@ -124,21 +140,38 @@ sub fixupNamespace { } my %classes = %$classes_ref; - $methods_ref = $classes{$class}; - next if not $methods_ref; + $methods_ref = $classes{$class}[0]; + $signals_ref = $classes{$class}[1]; + next if not ($methods_ref or $signals_ref); for ($method_node = $node->firstChild; $method_node; $method_node = $method_node->nextSibling ()) { - next if $method_node->nodeName ne "method"; + next if not ($method_node->nodeName eq "method" or $method_node->nodeName eq "constructor"); my $method; foreach $attr ($method_node->attributes) { - if ($attr->name eq "name") { + if (($attr->name eq "name" and $method_node->nodeName eq "method") or ($attr->name eq "cname" and $method_node->nodeName eq "constructor")) { $method = $attr->value; last; } } - next if not ${$methods_ref}{$method}; + next if not ${%$methods_ref}{$method}; + fixupParams ($method_node, $data_list_ref); } + + for ($signal_node = $node->firstChild; $signal_node; $signal_node = $signal_node->nextSibling ()) { + next if $signal_node->nodeName ne "signal"; + my $signal; + foreach $attr ($signal_node->attributes) { + if ($attr->name eq "name") { + $signal = $attr->value; + last; + } + } + next if not ${$signals_ref}{$signal}; + + fixupParams ($signal_node, $data_list_ref); + } + } } } @@ -152,8 +185,9 @@ sub fixup { return if not ($api_node and $api_node->nodeName eq "api"); for ($ns_node = $api_node->firstChild; $ns_node; $ns_node = $ns_node->nextSibling ()) { next if $ns_node->nodeName ne "namespace"; - next if not ($ns_node->attributes and (scalar (@{$ns_node->attributes})) + 1); + next if not $ns_node->attributes; my @attrs = $ns_node->attributes; + next if not @attrs; my $namespace = $attrs[0]->value; if (-f "$namespace.metadata") { if (not ($metadata and $metadata->{namespace} eq $namespace)) { diff --git a/parser/gapi2xml.pl b/parser/gapi2xml.pl index 8dfe0b50f..2cf6d92ba 100755 --- a/parser/gapi2xml.pl +++ b/parser/gapi2xml.pl @@ -88,7 +88,7 @@ while ($line = ) { $sdef =~ s!/\*.*?(\*/|\n)!!g; $sdef =~ s/\n\s*//g; $sdefs{$sname} = $sdef; - } elsif ($line =~ /^(\w+)_class_init\b/) { + } elsif ($line =~ /^(\w+)_(class|base)_init\b/) { $class = StudlyCaps($1); $pedef = $line; while ($line = ) { @@ -96,16 +96,25 @@ while ($line = ) { last if ($line =~ /^}/); } $pedefs{$class} = $pedef; - } elsif ($line =~ /g_boxed_type_register_static/) { - $boxdef = $line; - while ($line !~ /;/) { - $boxdef .= ($line = ); + } elsif ($line =~ /^(\w+)_get_type\b/) { + $class = StudlyCaps($1); + $pedef = $line; + while ($line = ) { + $pedef .= $line; + if ($line =~ /g_boxed_type_register_static/) { + $boxdef = $line; + while ($line !~ /;/) { + $boxdef .= ($line = ); + } + $boxdef =~ s/\n\s*//g; + $boxdef =~ /\(\"(\w+)\"/; + my $boxtype = $1; + $boxtype =~ s/($ns)Type(\w+)/$ns$2/; + $boxdefs{$boxtype} = $boxdef; + } + last if ($line =~ /^}/); } - $boxdef =~ s/\n\s*//g; - $boxdef =~ /\(\"(\w+)\"/; - my $boxtype = $1; - $boxtype =~ s/($ns)Type(\w+)/$ns$2/; - $boxdefs{$boxtype} = $boxdef; + $typefuncs{$class} = $pedef; } elsif ($line =~ /^(const|G_CONST_RETURN)?\s*\w+\s*\**\s*(\w+)\s*\(/) { $fname = $2; $fdef = ""; @@ -216,12 +225,21 @@ foreach $type (sort(keys(%ifaces))) { $iface = $ifaces{$type}; ($inst, $dontcare) = split(/:/, delete $objects{$type}); + $initfunc = $pedefs{$inst}; $ifacetype = delete $types{$iface}; delete $types{$inst}; - + $ifacecnt++; $iface_el = addNameElem($ns_elem, 'interface', $inst, $ns); addFuncElems($iface_el, $inst); + + $classdef = $sdefs{$1} if ($ifacetype =~ /struct\s+(\w+)/); + if ($initfunc) { + print "parsing $inst\n"; + parseInitFunc($iface_el, $initfunc); + } else { + warn "Don't have an init func for $inst.\n" if $debug; + } } @@ -234,6 +252,7 @@ foreach $type (sort(keys(%objects))) { ($inst, $class) = split(/:/, $objects{$type}); $class = $inst . "Class" if (!$class); $initfunc = $pedefs{$inst}; + $typefunc = $typefuncs{$inst}; $insttype = delete $types{$inst}; $classtype = delete $types{$class}; @@ -266,6 +285,13 @@ foreach $type (sort(keys(%objects))) { warn "Don't have an init func for $inst.\n" if $debug; } + # Get the interfaces from the class_init func. + if ($typefunc) { + parseTypeFunc($obj_el, $typefunc); + } else { + warn "Don't have a GetType func for $inst.\n" if $debug; + } + addFuncElems($obj_el, $inst); } @@ -379,12 +405,12 @@ sub addFuncElems $fcnt = keys(%fdefs); foreach $mname (keys(%fdefs)) { - next if ($mname !~ /$prefix/); + next if ($mname !~ /^$prefix/); if ($mname =~ /$prefix(new)/) { $el = addNameElem($obj_el, 'constructor', $mname); $drop_1st = 0; - } elsif ($fdefs{$mname} =~ /\(\s*$inst\b/) { + } elsif ($fdefs{$mname} =~ /\(\s*(const)?\s*$inst\b/) { $el = addNameElem($obj_el, 'method', $mname, $prefix); $fdefs{$mname} =~ /(.*?)\w+\s*\(/; addReturnElem($el, $1); @@ -579,6 +605,18 @@ sub addSignalElem } +sub addImplementsElem +{ + my ($spec, $node) = @_; + $spec =~ s/\n\s*//g; + if ($spec =~ /,\s*(\w+)_TYPE_(\w+),/) { + $impl_elem = $doc->createElement('interface'); + $name = StudlyCaps (lc ("$1_$2")); + $impl_elem->setAttribute ("cname", "$name"); + $node->appendChild($impl_elem); + } +} + sub parseInitFunc { @@ -612,6 +650,35 @@ sub parseInitFunc } } +sub parseTypeFunc +{ + my ($obj_el, $typefunc) = @_; + + my @type_lines = split (/\n/, $typefunc); + + my $linenum = 0; + $impl_node = undef; + while ($linenum < @type_lines) { + + my $line = $type_lines[$linenum]; + + if ($line =~ /#define/) { + # FIXME: This ignores the bool helper macro thingie. + } elsif ($line =~ /g_type_add_interface_static/) { + my $prop = $line; + do { + $prop .= $type_lines[++$linenum]; + } until ($type_lines[$linenum] =~ /;/); + if (not $impl_node) { + $impl_node = $doc->createElement ("implements"); + $obj_el->appendChild ($impl_node); + } + addImplementsElem ($prop, $impl_node); + } + $linenum++; + } +} + ############################################################## # Converts a dash or underscore separated name to StudlyCaps. ############################################################## diff --git a/parser/gapi_pp.pl b/parser/gapi_pp.pl index 5afd23916..b7aa82233 100755 --- a/parser/gapi_pp.pl +++ b/parser/gapi_pp.pl @@ -70,18 +70,12 @@ foreach $fname (`ls $ARGV[0]/*.c`, @privhdrs) { } while ($line = ) { - next if ($line !~ /^(struct|\w+_class_init)|g_boxed_type_register_static/); + #next if ($line !~ /^(struct|\w+_class_init)|g_boxed_type_register_static/); + next if ($line !~ /^(struct|\w+_class_init|\w+_base_init|\w+_get_type)/); if ($line =~ /^struct/) { # need some of these to parse out parent types print "private"; - } elsif ($line =~ /g_boxed_type_register_static/) { - while ($line !~ /;/) { - print $line; - $line = ; - } - print $line; - next; } do { diff --git a/sample/ButtonApp.cs b/sample/ButtonApp.cs index 1e1afb078..301c8e9b6 100755 --- a/sample/ButtonApp.cs +++ b/sample/ButtonApp.cs @@ -21,7 +21,7 @@ namespace GtkSamples { win.DeleteEvent += new EventHandler (Window_Delete); Button btn = new Button ("Click Me"); btn.Clicked += new EventHandler (btn_click); - win.EmitAdd (btn); + win.Add (btn); win.ShowAll (); Application.Run (); return 0; diff --git a/sample/Menu.cs b/sample/Menu.cs index 3cf336f09..731f3f127 100755 --- a/sample/Menu.cs +++ b/sample/Menu.cs @@ -25,17 +25,17 @@ namespace GtkSharp.Samples { MenuBar mb = new MenuBar (); Menu file_menu = new Menu (); MenuItem exit_item = new MenuItem("Exit"); - exit_item.Activate += new EventHandler (exit_cb); + exit_item.Activated += new EventHandler (exit_cb); file_menu.Append (exit_item); MenuItem file_item = new MenuItem("File"); - file_item.SetSubmenu (file_menu); + file_item.Submenu = file_menu; mb.Append (file_item); box.PackStart(mb, false, false, 0); Button btn = new Button ("Yep, that's a menu"); box.PackStart(btn, true, true, 0); - win.EmitAdd (box); + win.Add (box); win.ShowAll (); Application.Run (); diff --git a/sources/Atk.metadata b/sources/Atk.metadata new file mode 100644 index 000000000..bb1f17e50 --- /dev/null +++ b/sources/Atk.metadata @@ -0,0 +1,28 @@ + + + + + + + GetDocument + + + + name + GetTheDocument + + + + + + SetDocument + + + + name + SetTheDocument + + + + + diff --git a/sources/Gtk.metadata b/sources/Gtk.metadata index f80180b68..1ef7b2467 100644 --- a/sources/Gtk.metadata +++ b/sources/Gtk.metadata @@ -1,5 +1,7 @@ + + GetIterAtLineOffset @@ -28,4 +30,892 @@ + + + InsertText + + + + gint* + pass_as + out + + + + + + + + gtk_tree_store_newv + + + + va_type + length_param + + + + + + + + GetEditable + + + + name + GetIsEditable + + + + + + SetEditable + + + + name + SetIsEditable + + + + + + Add + + + + name + Added + + + + + + Remove + + + + name + Removed + + + + + + InsertText + + + + name + TextInserted + + + + + + DeleteText + + + + name + TextDeleted + + + + + + Show + + + + name + Shown + + + + + + Hide + + + + name + Hidden + + + + + + Map + + + + name + Mapped + + + + + + Unmap + + + + name + Unmapped + + + + + + Realize + + + + name + Realized + + + + + + Unrealize + + + + name + Unrealized + + + + + + GrabFocus + + + + name + FocusGrabbed + + + + + + SizeAllocate + + + + name + SizeAllocated + + + + + + MnemonicActivate + + + + name + MnemonicActivated + + + + + + SizeRequest + + + + name + SizeRequested + + + + + + ChildNotify + + + + name + ChildNotified + + + + + + + InsertPixbuf + + + + name + PixbufInserted + + + + + + ApplyTag + + + + name + TagApplied + + + + + + RemoveTag + + + + name + TagRemoved + + + + + + InsertChildAnchor + + + + name + ChildAnchorInserted + + + + + + RemoveChildAnchor + + + + name + ChildAnchorRemoved + + + + + + Select + + + + name + Selected + + + + + + Deselect + + + + name + Deselected + + + + + + Toggle + + + + name + Toggled + + + + + + SelectChild + + + + name + ChildSelected + + + + + + UnselectChild + + + + name + ChildUnselected + + + + + + SelectChild + + + + name + ChildSelected + + + + + + UnselectChild + + + + name + ChildUnselected + + + + + + + StartQuery + + + + name + QueryStarted + + + + + + StopQuery + + + + name + QueryStopped + + + + + + Collapse + + + + name + Collapsed + + + + + + Expand + + + + name + Expanded + + + + + + SetFocusChild + + + + name + FocusChildSet + + + + + + PasteClipboard + + + + name + ClipboardPasted + + + + + + CutClipboard + + + + name + ClipboardCut + + + + + + CopyClipboard + + + + name + ClipboardCopied + + + + + + PasteClipboard + + + + name + ClipboardPasted + + + + + + CutClipboard + + + + name + ClipboardCut + + + + + + CopyClipboard + + + + name + ClipboardCopied + + + + + + Activate + + + + name + Activated + + + + + + Deactivate + + + + name + Deactivated + + + + + + Deactivate + + + + name + Deactivated + + + + + + ToggleSizeRequest + + + + name + ToggleSizeRequested + + + + + + ToggleSizeAllocate + + + + name + ToggleSizeAllocated + + + + + + RemoveWidget + + + + name + WidgetRemoved + + + + + + SizeAllocate + + + + name + SizeAllocated + + + + + + MnemonicActivate + + + + name + MnemonicActivated + + + + + + SizeRequest + + + + name + SizeRequested + + + + + + ChildNotify + + + + name + ChildNotified + + + + + + Toggled + + + + name + Toggle + + + + + + Pressed + + + + name + Press + + + + + + Clicked + + + + name + Click + + + + + + Released + + + + name + Release + + + + + + Enter + + + + name + Entered + + + + + + Leave + + + + name + Left + + + + + + Deactivate + + + + name + Deactivated + + + + + + RemoveWidget + + + + name + WidgetRemoved + + + + + + EditingDone + + + + name + FinishEditing + + + + + + ActivateDefault + + + + name + DefaultActivated + + + + + + ActivateFocus + + + + name + FocusActivated + + + + + + Changed + + + + name + Change + + + + + + ValueChanged + + + + name + ChangeValue + + + + + + Destroy + + + + name + Destroyed + + + + + + RowActivated + + + + name + ActivateRow + + + + + + RowExpanded + + + + name + RowExpand + + + + + + RowDeleted + + + + name + DeleteRow + + + + + + RowHasChildToggled + + + + name + ToggleRowHasChild + + + + + + RowInserted + + + + name + InsertRow + + + + + + RowChanged + + + + name + ChangeRow + + + + + + RowsReordered + + + + name + ReorderRows + + + + + + SortColumnChanged + + + + name + ChangeSortColumn + + + + + + Response + + + + name + Respond + + + + + + EndUserAction + + + + name + UserActionEnded + + + + + + BeginUserAction + + + + name + UserActionBegun + + + + + + Toggled + + + + name + Toggle + + + + + + CheckResize + + + + name + ResizeChecked + + + + + + Clicked + + + + name + Click + + + +