From ea489c23535d1247ec2117a1d1074ccb016d4eef Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Mon, 24 Jan 2005 18:25:02 +0000 Subject: [PATCH] 2005-01-24 Mike Kestner * gda/Makefile.am : add new custom. * gda/XmlConnection.custom : add backcompat static ctor. * generator/ClassBase.cs : refactor lookup logic to here from Ctor and improve the collision resolution. * generator/Ctor.cs : refactor to use MethodBase. * generator/Makefile.am : add new file. * generator/MethodBase.cs : new base class for ctors and methods. * generator/Method.cs : refactor to use MethodBase. * generator/StructBase.cs : move some logic from here to Ctor. * gnome/CanvasPathDef.custom : add backcompat static ctor. * gnome/GPPath.custom : add backcompat static ctor. * gnome/Makefile.am : add new custom. * gtk/Gtk.metadata : mark a colliding Button ctor shared. svn path=/trunk/gtk-sharp/; revision=39431 --- ChangeLog | 16 ++++ doc/en/Gda/XmlConnection.xml | 16 +++- doc/en/Gdk/PixbufLoader.xml | 32 +++---- doc/en/Gnome/CanvasPathDef.xml | 14 +++ doc/en/Gnome/GPPath.xml | 14 +++ doc/en/Gnome/Pixmap.xml | 40 ++++---- doc/en/Gtk/CellView.xml | 32 +++---- gda/Makefile.am | 3 +- gda/XmlConnection.custom | 26 +++++ generator/ClassBase.cs | 53 ++++++----- generator/Ctor.cs | 167 +++++++++++---------------------- generator/Makefile.am | 1 + generator/Method.cs | 127 +++++++------------------ generator/MethodBase.cs | 133 ++++++++++++++++++++++++++ generator/StructBase.cs | 7 +- gnome/CanvasPathDef.custom | 26 +++++ gnome/GPPath.custom | 26 +++++ gnome/Makefile.am | 1 + gtk/Gtk.metadata | 1 + 19 files changed, 445 insertions(+), 290 deletions(-) create mode 100644 gda/XmlConnection.custom create mode 100644 generator/MethodBase.cs create mode 100644 gnome/CanvasPathDef.custom create mode 100644 gnome/GPPath.custom diff --git a/ChangeLog b/ChangeLog index c9f9acfab..e4b1f565a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2005-01-24 Mike Kestner + + * gda/Makefile.am : add new custom. + * gda/XmlConnection.custom : add backcompat static ctor. + * generator/ClassBase.cs : refactor lookup logic to here from Ctor + and improve the collision resolution. + * generator/Ctor.cs : refactor to use MethodBase. + * generator/Makefile.am : add new file. + * generator/MethodBase.cs : new base class for ctors and methods. + * generator/Method.cs : refactor to use MethodBase. + * generator/StructBase.cs : move some logic from here to Ctor. + * gnome/CanvasPathDef.custom : add backcompat static ctor. + * gnome/GPPath.custom : add backcompat static ctor. + * gnome/Makefile.am : add new custom. + * gtk/Gtk.metadata : mark a colliding Button ctor shared. + 2005-01-23 Jeroen Zwartepoorte * gtk/ActionGroup.custom: Add a string index for the GetAction method. diff --git a/doc/en/Gda/XmlConnection.xml b/doc/en/Gda/XmlConnection.xml index 175381cc1..6e1783450 100644 --- a/doc/en/Gda/XmlConnection.xml +++ b/doc/en/Gda/XmlConnection.xml @@ -229,5 +229,19 @@ Gets / Sets the data source name for the object. Chain to this constructor if you have manually registered a native value for your subclass. + + + Constructor + + + + + + Creates a Connection object from the contents of file. + a path to a .connection file. + a + The file must be a properly formatted .connection file. + + - \ No newline at end of file + diff --git a/doc/en/Gdk/PixbufLoader.xml b/doc/en/Gdk/PixbufLoader.xml index 4d710b48e..2d3173863 100644 --- a/doc/en/Gdk/PixbufLoader.xml +++ b/doc/en/Gdk/PixbufLoader.xml @@ -420,22 +420,6 @@ namespace GtkDemo This is an overload to , which determines the length automatically. - - - Method - - Gdk.PixbufLoader - - - - - - To be added - a - a - To be added - - Method @@ -452,5 +436,19 @@ namespace GtkDemo To be added + + + Constructor + + + + + + To be added + a + a + To be added + + - \ No newline at end of file + diff --git a/doc/en/Gnome/CanvasPathDef.xml b/doc/en/Gnome/CanvasPathDef.xml index f3886ab49..c29d71ae6 100644 --- a/doc/en/Gnome/CanvasPathDef.xml +++ b/doc/en/Gnome/CanvasPathDef.xml @@ -516,5 +516,19 @@ To be added + + + Constructor + + + + + + To be added + a + a + To be added + + \ No newline at end of file diff --git a/doc/en/Gnome/GPPath.xml b/doc/en/Gnome/GPPath.xml index de2652e4d..a949773b3 100644 --- a/doc/en/Gnome/GPPath.xml +++ b/doc/en/Gnome/GPPath.xml @@ -516,5 +516,19 @@ To be added + + + Constructor + + + + + + To be added + a + a + To be added + + \ No newline at end of file diff --git a/doc/en/Gnome/Pixmap.xml b/doc/en/Gnome/Pixmap.xml index d7a9a27eb..8273d633c 100644 --- a/doc/en/Gnome/Pixmap.xml +++ b/doc/en/Gnome/Pixmap.xml @@ -32,26 +32,6 @@ - - - Method - - Gnome.Pixmap - - - - - - - - To be added - a - a - a - a - To be added - - Method @@ -238,5 +218,23 @@ Returns the native value for . + + + Constructor + + + + + + + + To be added + a + a + a + a + To be added + + - \ No newline at end of file + diff --git a/doc/en/Gtk/CellView.xml b/doc/en/Gtk/CellView.xml index e3e10cd9e..3c5009f7e 100644 --- a/doc/en/Gtk/CellView.xml +++ b/doc/en/Gtk/CellView.xml @@ -31,22 +31,6 @@ - - - Method - - Gtk.CellView - - - - - - Creates a new widget, adds a to it, and makes it show . - a - a - - - Method @@ -393,7 +377,21 @@ Sets the attribute to model column bindings for a renderer. a a - The array should consist of pairs of attribute name and column index. + The array should consist of pairs of attribute name and column index. + + + + + Constructor + + + + + + Creates a new widget, adds a to it, and makes it show . + a + a + diff --git a/gda/Makefile.am b/gda/Makefile.am index 34a41a797..a726d64af 100644 --- a/gda/Makefile.am +++ b/gda/Makefile.am @@ -12,7 +12,8 @@ references = ../glib/glib-sharp.dll sources = \ Application.cs -customs = +customs = \ + XmlConnection.custom add_dist = gda-sharp-2.0.pc.in diff --git a/gda/XmlConnection.custom b/gda/XmlConnection.custom new file mode 100644 index 000000000..3fe05aac9 --- /dev/null +++ b/gda/XmlConnection.custom @@ -0,0 +1,26 @@ +// Gda.XmlConnection.custom - XmlConnection class customizations +// +// Author: Mike Kestner +// +// Copyright (C) 2005 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + + public static XmlConnection NewFromFile (string filename) + { + return new XmlConnection (gda_xml_connection_new_from_file (filename)); + } + diff --git a/generator/ClassBase.cs b/generator/ClassBase.cs index 26c07bf15..709cbc304 100644 --- a/generator/ClassBase.cs +++ b/generator/ClassBase.cs @@ -83,7 +83,7 @@ namespace GtkSharp.Generation { name = member.GetAttribute("name"); while (methods.ContainsKey(name)) name += "mangled"; - methods.Add (name, new Method (LibraryName, member, this)); + methods.Add (name, new Method (member, this)); break; case "property": @@ -105,7 +105,7 @@ namespace GtkSharp.Generation { break; case "constructor": - ctors.Add (new Ctor (LibraryName, member, this)); + ctors.Add (new Ctor (member, this)); break; default: @@ -332,45 +332,52 @@ namespace GtkSharp.Generation { public ArrayList Ctors { get { return ctors; } } + bool HasStaticCtor (string name) + { + if (Parent != null && Parent.HasStaticCtor (name)) + return true; + + foreach (Ctor ctor in Ctors) + if (ctor.StaticName == name) + return true; + + return false; + } + private void InitializeCtors () { if (ctors_initted) return; + if (Parent != null) + Parent.InitializeCtors (); + ArrayList valid_ctors = new ArrayList(); clash_map = new Hashtable(); - bool has_preferred = false; foreach (Ctor ctor in ctors) { if (ctor.Validate ()) { - ctor.InitClashMap (clash_map); - if (ctor.Preferred) - has_preferred = true; - + if (clash_map.Contains (ctor.Signature.Types)) { + Ctor clash = clash_map [ctor.Signature.Types] as Ctor; + Ctor alter = ctor.Preferred ? clash : ctor; + alter.IsStatic = true; + if (Parent != null && Parent.HasStaticCtor (alter.StaticName)) + alter.Modifiers = "new "; + } else + clash_map [ctor.Signature.Types] = ctor; + valid_ctors.Add (ctor); - } - else - Console.WriteLine("in Object " + QualifiedName); + } else + Console.WriteLine("in Type " + QualifiedName); } + ctors = valid_ctors; - - if (!has_preferred && ctors.Count > 0) - ((Ctor) ctors[0]).Preferred = true; - - foreach (Ctor ctor in ctors) - ctor.Initialize (clash_map); - ctors_initted = true; } protected virtual void GenCtors (GenerationInfo gen_info) { - ClassBase klass = this; - while (klass != null) { - klass.InitializeCtors (); - klass = klass.Parent; - } - + InitializeCtors (); foreach (Ctor ctor in ctors) ctor.Generate (gen_info); } diff --git a/generator/Ctor.cs b/generator/Ctor.cs index af0306e37..9a6f7a444 100644 --- a/generator/Ctor.cs +++ b/generator/Ctor.cs @@ -1,9 +1,9 @@ // GtkSharp.Generation.Ctor.cs - The Constructor Generation Class. // -// Author: Mike Kestner +// Author: Mike Kestner // // Copyright (c) 2001-2003 Mike Kestner -// Copyright (c) 2004 Novell, Inc. +// Copyright (c) 2004-2005 Novell, Inc. // // This program is free software; you can redistribute it and/or // modify it under the terms of version 2 of the GNU General Public @@ -27,147 +27,88 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public class Ctor { + public class Ctor : MethodBase { - private string libname; - private XmlElement elem; - private Parameters parms; - private Signature sig = null; - private ImportSignature isig = null; - private MethodBody body = null; private bool preferred; - private string clashName = null; - private ClassBase container_type; - private bool force_static; + private string name; private bool needs_chaining = false; + public Ctor (XmlElement elem, ClassBase implementor) : base (elem, implementor) + { + if (elem.HasAttribute ("preferred")) + preferred = true; + if (implementor is ObjectGen) + needs_chaining = true; + name = implementor.Name; + } + public bool Preferred { get { return preferred; } set { preferred = value; } } - public bool ForceStatic { - get { return force_static; } - set { force_static = value; } - } - - public Parameters Params { - get { return parms; } - } + public string StaticName { + get { + if (!IsStatic) + return String.Empty; - public Ctor (string libname, XmlElement elem, ClassBase container_type) { - this.libname = libname; - this.elem = elem; - this.container_type = container_type; - XmlElement parms_elem = elem ["parameters"]; - if (parms_elem != null) - parms = new Parameters (parms_elem, container_type.NS); - if (elem.HasAttribute ("preferred")) - preferred = true; - if (container_type is ObjectGen) - needs_chaining = true; - } + string[] toks = CName.Substring(CName.IndexOf("new")).Split ('_'); + string result = String.Empty; - public bool Validate () - { - if (parms != null) { - if (!parms.Validate ()) { - Console.Write("in ctor "); - Statistics.ThrottledCount++; - return false; - } + foreach (string tok in toks) + result += tok.Substring(0,1).ToUpper() + tok.Substring(1); + return result; } - sig = new Signature (parms); - isig = new ImportSignature (parms, container_type.NS); - body = new MethodBody (parms, container_type.NS); - - return true; } - public void InitClashMap (Hashtable clash_map) + public void GenerateImport (StreamWriter sw) { - if (clash_map.ContainsKey (sig.Types)) { - int num = (int) clash_map[sig.Types]; - clash_map[sig.Types] = ++num; - } + sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\")]"); + sw.WriteLine("\t\tstatic extern " + Safety + "IntPtr " + CName + "(" + ImportSignature + ");"); + sw.WriteLine(); + } + + public void GenerateStatic (GenerationInfo gen_info) + { + StreamWriter sw = gen_info.Writer; + sw.WriteLine("\t\tpublic static " + Safety + Modifiers + name + " " + StaticName + "(" + Signature + ")"); + sw.WriteLine("\t\t{"); + + Body.Initialize(gen_info, false, false, ""); + + sw.Write("\t\t\treturn "); + if (container_type is StructBase) + sw.Write ("{0}.New (", name); else - clash_map[sig.Types] = 0; + sw.Write ("new {0} (", name); + sw.WriteLine (CName + "(" + Body.GetCallString (false) + "));"); } - public void Initialize (Hashtable clash_map) - { - int clashes = (int) clash_map[sig.Types]; - string cname = elem.GetAttribute("cname"); - if (force_static || (clashes > 0 && !Preferred)) { - 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); - } - clashName = mname + "(" + sig.ToString () + ")"; - } - } - public void Generate (GenerationInfo gen_info) { StreamWriter sw = gen_info.Writer; - string cname = elem.GetAttribute("cname"); - string name = ((XmlElement)elem.ParentNode).GetAttribute("name"); - string safety; - if (body.ThrowsException) - safety = "unsafe "; - else - safety = ""; - SymbolTable table = SymbolTable.Table; - sw.WriteLine("\t\t[DllImport(\"" + libname + "\")]"); - sw.WriteLine("\t\tstatic extern " + safety + "IntPtr " + cname + "(" + isig.ToString () + ");"); - sw.WriteLine(); + GenerateImport (sw); - if (clashName != null) { - string modifiers = ""; - Ctor dup = null; - ObjectGen parent = (ObjectGen) container_type.Parent; - while (dup == null && parent != null) { - foreach (Ctor c in parent.Ctors) { - if (c.clashName == clashName) { - dup = c; - modifiers = "new "; - break; - } - } - parent = (ObjectGen) parent.Parent; - } - - sw.WriteLine("\t\tpublic static " + safety + modifiers + name + " " + clashName); - sw.WriteLine("\t\t{"); - - body.Initialize(gen_info, false, false, ""); - - sw.Write("\t\t\treturn "); - if (container_type is StructBase) - sw.Write ("{0}.New (", name); - else - sw.Write ("new {0} (", name); - sw.WriteLine (cname + "(" + body.GetCallString (false) + "));"); - } else { - sw.WriteLine("\t\tpublic {0}{1} ({2}) {3}", safety, name, sig.ToString(), needs_chaining ? ": base (IntPtr.Zero)" : ""); + if (IsStatic) + GenerateStatic (gen_info); + else { + sw.WriteLine("\t\tpublic {0}{1} ({2}) {3}", Safety, name, Signature.ToString(), needs_chaining ? ": base (IntPtr.Zero)" : ""); sw.WriteLine("\t\t{"); if (needs_chaining) { sw.WriteLine ("\t\t\tif (GetType () != typeof (" + name + ")) {"); - if (Params == null || Params.Count == 0) { + if (Parameters == null || Parameters.Count == 0) { sw.WriteLine ("\t\t\t\tCreateNativeObject (new string [0], new GLib.Value[0]);"); sw.WriteLine ("\t\t\t\treturn;"); } else { ArrayList names = new ArrayList (); ArrayList values = new ArrayList (); - for (int i = 0; i < Params.Count; i++) { - Parameter p = Params[i]; + for (int i = 0; i < Parameters.Count; i++) { + Parameter p = Parameters[i]; if (container_type.GetPropertyRecursively (p.StudlyName) != null) { names.Add (p.Name); values.Add (p.Name); @@ -177,11 +118,11 @@ namespace GtkSharp.Generation { } } - if (names.Count == Params.Count) { + if (names.Count == Parameters.Count) { sw.WriteLine ("\t\t\t\tArrayList vals = new ArrayList();"); sw.WriteLine ("\t\t\t\tArrayList names = new ArrayList();"); for (int i = 0; i < names.Count; i++) { - Parameter p = Params [i]; + Parameter p = Parameters [i]; string indent = "\t\t\t\t"; if (p.NullOk && p.Generatable is ObjectGen) { sw.WriteLine (indent + "if (" + p.Name + " != null) {"); @@ -208,9 +149,9 @@ namespace GtkSharp.Generation { sw.WriteLine ("\t\t\t}"); } - body.Initialize(gen_info, false, false, ""); - sw.WriteLine("\t\t\t{0} = {1}({2});", container_type.AssignToName, cname, body.GetCallString (false)); - body.HandleException (sw, ""); + Body.Initialize(gen_info, false, false, ""); + sw.WriteLine("\t\t\t{0} = {1}({2});", container_type.AssignToName, CName, Body.GetCallString (false)); + Body.HandleException (sw, ""); } sw.WriteLine("\t\t}"); diff --git a/generator/Makefile.am b/generator/Makefile.am index 567f21517..a0ee1a404 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -29,6 +29,7 @@ sources = \ ManagedCallString.cs \ ManualGen.cs \ MarshalGen.cs \ + MethodBase.cs \ MethodBody.cs \ Method.cs \ ObjectGen.cs \ diff --git a/generator/Method.cs b/generator/Method.cs index 1ffa25d11..4f58e4283 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -27,53 +27,25 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public class Method { + public class Method : MethodBase { - private string libname; - private XmlElement elem; private ReturnValue retval; - private Parameters parms; - private Signature sig; - private ImportSignature isig; - private MethodBody body; - private ClassBase container_type; private bool initialized = false; private string call; private string name; private string protection = "public"; private bool is_get, is_set; - private bool needs_ref = false; private bool deprecated = false; - public Method (string libname, XmlElement elem, ClassBase container_type) + public Method (XmlElement elem, ClassBase container_type) : base (elem, container_type) { - this.elem = elem; this.retval = new ReturnValue (elem["return-type"]); - if (elem["parameters"] != null) { - parms = new Parameters (elem["parameters"], container_type.NS); - parms.Static = IsShared; - } - this.container_type = container_type; if (!container_type.IsDeprecated && elem.HasAttribute ("deprecated")) deprecated = elem.GetAttribute ("deprecated") == "1"; this.name = elem.GetAttribute("name"); if (name == "GetType") name = "GetGType"; - if (elem.HasAttribute ("library")) - this.libname = elem.GetAttribute ("library"); - else - this.libname = libname; - - // caller does not own reference? - if (elem.HasAttribute ("needs_ref")) - this.needs_ref = (elem.GetAttribute ("needs_ref") == "1"); - } - - public string CName { - get { - return elem.GetAttribute ("cname"); - } } public bool IsDeprecated { @@ -94,12 +66,6 @@ namespace GtkSharp.Generation { } } - private bool IsShared { - get { - return elem.GetAttribute ("shared") == "true"; - } - } - public string Name { get { return name; @@ -124,21 +90,6 @@ namespace GtkSharp.Generation { } } - string Safety { - get { - if (body.ThrowsException && !(container_type is InterfaceGen)) - return "unsafe "; - else - return ""; - } - } - - public Signature Signature { - get { - return sig; - } - } - public override bool Equals (object o) { if (!(o is Method)) @@ -168,32 +119,26 @@ namespace GtkSharp.Generation { if (initialized) return true; + Parameters parms = Parameters; is_get = (((parms != null && ((parms.IsAccessor && retval.CSType == "void") || (parms.Count == 0 && retval.CSType != "void"))) || (parms == null && retval.CSType != "void")) && Name.Length > 3 && (Name.StartsWith ("Get") || Name.StartsWith ("Is") || Name.StartsWith ("Has"))); is_set = ((parms != null && (parms.IsAccessor || (parms.Count == 1 && retval.CSType == "void"))) && (Name.Length > 3 && Name.Substring(0, 3) == "Set")); - sig = new Signature (parms); - isig = new ImportSignature (parms, container_type.NS); - body = new MethodBody (parms, container_type.NS); - call = "(" + (IsShared ? "" : container_type.CallByName () + (parms != null ? ", " : "")) + body.GetCallString (is_set) + ")"; + call = "(" + (IsStatic ? "" : container_type.CallByName () + (parms != null ? ", " : "")) + Body.GetCallString (is_set) + ")"; initialized = true; return true; } - public bool Validate () + public override bool Validate () { - if (!Initialize ()) + if (!Initialize () || !base.Validate ()) return false; - if (parms != null && !parms.Validate ()) { - Console.Write ("in method " + Name + " "); - return false; - } - if (!retval.Validate ()) { Console.Write(" in method " + Name + " "); return false; } + return true; } @@ -205,18 +150,18 @@ namespace GtkSharp.Generation { else complement = 'G'; - return container_type.GetMethod (complement + elem.GetAttribute("name").Substring (1)); + return container_type.GetMethod (complement + name.Substring (1)); } public string Declaration { get { - return retval.CSType + " " + Name + " (" + (sig != null ? sig.ToString() : "") + ");"; + return retval.CSType + " " + Name + " (" + (Signature != null ? Signature.ToString() : "") + ");"; } } private void GenerateDeclCommon (StreamWriter sw, ClassBase implementor) { - if (elem.GetAttribute ("shared") == "true") + if (IsStatic) sw.Write("static "); sw.Write (Safety); Method dup = null; @@ -225,16 +170,16 @@ namespace GtkSharp.Generation { if (implementor != null) dup = implementor.GetMethodRecursively (Name); - if (Name == "ToString" && parms == null) + if (Name == "ToString" && Parameters == null) sw.Write("override "); else if (Name == "GetGType" && container_type is ObjectGen) sw.Write("new "); - else if (elem.HasAttribute("new_flag") || (dup != null && dup.Initialize () && ((dup.Signature != null && sig != null && dup.Signature.ToString() == sig.ToString()) || (dup.Signature == null && sig == null)))) + else if (Modifiers == "new " || (dup != null && dup.Initialize () && ((dup.Signature != null && Signature != null && dup.Signature.ToString() == Signature.ToString()) || (dup.Signature == null && Signature == null)))) sw.Write("new "); if (is_get || is_set) { if (retval.CSType == "void") - sw.Write (parms.AccessorReturnType); + sw.Write (Parameters.AccessorReturnType); else sw.Write(retval.CSType); sw.Write(" "); @@ -244,9 +189,9 @@ namespace GtkSharp.Generation { sw.Write (Name); sw.WriteLine(" { "); } else if (IsAccessor) { - sw.Write (sig.AccessorType + " " + Name + "(" + sig.AsAccessor + ")"); + sw.Write (Signature.AccessorType + " " + Name + "(" + Signature.AsAccessor + ")"); } else { - sw.Write(retval.CSType + " " + Name + "(" + (sig != null ? sig.ToString() : "") + ")"); + sw.Write(retval.CSType + " " + Name + "(" + (Signature != null ? Signature.ToString() : "") + ")"); } } @@ -255,8 +200,7 @@ namespace GtkSharp.Generation { if (!Initialize ()) return; - if (elem.HasAttribute("shared") && - (elem.GetAttribute("shared") == "true")) + if (IsStatic) return; if (is_get || is_set) @@ -290,10 +234,10 @@ namespace GtkSharp.Generation { public void GenerateImport (StreamWriter sw) { - string import_sig = IsShared ? "" : container_type.MarshalType + " raw"; - import_sig += !IsShared && parms != null ? ", " : ""; - import_sig += isig.ToString(); - sw.WriteLine("\t\t[DllImport(\"" + libname + "\")]"); + string import_sig = IsStatic ? "" : container_type.MarshalType + " raw"; + import_sig += !IsStatic && Parameters != null ? ", " : ""; + import_sig += ImportSignature.ToString(); + sw.WriteLine("\t\t[DllImport(\"" + LibraryName + "\")]"); if (retval.MarshalType.StartsWith ("[return:")) sw.WriteLine("\t\t" + retval.MarshalType + " static extern " + Safety + retval.CSType + " " + CName + "(" + import_sig + ");"); else @@ -308,22 +252,21 @@ namespace GtkSharp.Generation { if (!Initialize ()) return; - if (implementor != null && elem.HasAttribute("shared") && - (elem.GetAttribute ("shared") == "true")) + if (implementor != null && IsStatic) return; /* we are generated by the get Method, if there is one */ if (is_set || is_get) { - if (!elem.HasAttribute("new_flag") && container_type.GetPropertyRecursively (Name.Substring (3)) != null) + if (Modifiers != "new " && container_type.GetPropertyRecursively (Name.Substring (3)) != null) return; comp = GetComplement (); - if (comp != null && comp.Validate () && is_set && parms.AccessorReturnType == comp.ReturnType) + if (comp != null && comp.Validate () && is_set && Parameters.AccessorReturnType == comp.ReturnType) return; - if (comp != null && is_set && parms.AccessorReturnType != comp.ReturnType) + if (comp != null && is_set && Parameters.AccessorReturnType != comp.ReturnType) { is_set = false; - call = "(Handle, " + body.GetCallString (false) + ")"; + call = "(Handle, " + Body.GetCallString (false) + ")"; comp = null; } /* some setters take more than one arg */ @@ -332,7 +275,7 @@ namespace GtkSharp.Generation { } GenerateImport (gen_info.Writer); - if (comp != null && retval.CSType == comp.parms.AccessorReturnType) + if (comp != null && retval.CSType == comp.Parameters.AccessorReturnType) comp.GenerateImport (gen_info.Writer); if (IsDeprecated) @@ -353,7 +296,7 @@ namespace GtkSharp.Generation { if (is_get || is_set) { - if (comp != null && retval.CSType == comp.parms.AccessorReturnType) + if (comp != null && retval.CSType == comp.Parameters.AccessorReturnType) { gen_info.Writer.WriteLine (); gen_info.Writer.Write ("\t\t\tset"); @@ -375,8 +318,8 @@ namespace GtkSharp.Generation { StreamWriter sw = gen_info.Writer; sw.WriteLine(" {"); if (IsAccessor) - body.InitAccessor (sw, sig, indent); - body.Initialize(gen_info, is_get, is_set, indent); + Body.InitAccessor (sw, Signature, indent); + Body.Initialize(gen_info, is_get, is_set, indent); SymbolTable table = SymbolTable.Table; IGeneratable ret_igen = table [retval.CType]; @@ -400,22 +343,22 @@ namespace GtkSharp.Generation { sw.WriteLine(retval.CSType + " ret = " + table.FromNativeReturn(retval.CType, raw_parms) + ";"); } - body.Finish (sw, indent); - body.HandleException (sw, indent); + Body.Finish (sw, indent); + Body.HandleException (sw, indent); - if (is_get && parms != null) - sw.WriteLine (indent + "\t\t\treturn " + parms.AccessorName + ";"); + if (is_get && Parameters != null) + sw.WriteLine (indent + "\t\t\treturn " + Parameters.AccessorName + ";"); else if (retval.MarshalType != "void") sw.WriteLine (indent + "\t\t\treturn ret;"); else if (IsAccessor) - body.FinishAccessor (sw, sig, indent); + Body.FinishAccessor (sw, Signature, indent); sw.Write(indent + "\t\t}"); } bool IsAccessor { get { - return retval.CSType == "void" && sig.IsAccessor; + return retval.CSType == "void" && Signature.IsAccessor; } } } diff --git a/generator/MethodBase.cs b/generator/MethodBase.cs new file mode 100644 index 000000000..81c2123e0 --- /dev/null +++ b/generator/MethodBase.cs @@ -0,0 +1,133 @@ +// GtkSharp.Generation.MethodBase.cs - function element base class. +// +// Author: Mike Kestner +// +// Copyright (c) 2001-2003 Mike Kestner +// Copyright (c) 2004-2005 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +namespace GtkSharp.Generation { + + using System; + using System.Xml; + + public abstract class MethodBase { + + XmlElement elem; + protected ClassBase container_type; + Parameters parms; + bool is_static = false; + string mods = String.Empty; + + protected MethodBase (XmlElement elem, ClassBase container_type) + { + this.elem = elem; + this.container_type = container_type; + XmlElement parms_elem = elem ["parameters"]; + if (parms_elem != null) + parms = new Parameters (parms_elem, container_type.NS); + IsStatic = elem.GetAttribute ("shared") == "true"; + if (elem.HasAttribute ("new_flag")) + mods = "new "; + } + + MethodBody body; + public MethodBody Body { + get { + if (body == null) + body = new MethodBody (parms, container_type.NS); + return body; + } + } + + public string CName { + get { + return elem.GetAttribute ("cname"); + } + } + + ImportSignature isig; + public ImportSignature ImportSignature { + get { + if (isig == null) + isig = new ImportSignature (parms, container_type.NS); + return isig; + } + } + + public bool IsStatic { + get { + return is_static; + } + set { + is_static = value; + if (parms != null) + parms.Static = value; + } + } + + public string LibraryName { + get { + if (elem.HasAttribute ("library")) + return elem.GetAttribute ("library"); + return container_type.LibraryName; + } + } + + public string Modifiers { + get { + return mods; + } + set { + mods = value; + } + } + + protected Parameters Parameters { + get { + return parms; + } + } + + protected string Safety { + get { + return Body.ThrowsException && !(container_type is InterfaceGen) ? "unsafe " : ""; + } + } + + Signature sig; + public Signature Signature { + get { + if (sig == null) + sig = new Signature (parms); + return sig; + } + } + + public virtual bool Validate () + { + if (parms != null && !parms.Validate ()) { + Console.Write("in ctor "); + Statistics.ThrottledCount++; + return false; + } + + return true; + } + } +} + diff --git a/generator/StructBase.cs b/generator/StructBase.cs index e52a45728..ea84bb667 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -186,11 +186,8 @@ namespace GtkSharp.Generation { sw.WriteLine (); } - foreach (Ctor ctor in Ctors) { - ctor.ForceStatic = true; - if (ctor.Params != null) - ctor.Params.Static = true; - } + foreach (Ctor ctor in Ctors) + ctor.IsStatic = true; base.GenCtors (gen_info); } diff --git a/gnome/CanvasPathDef.custom b/gnome/CanvasPathDef.custom new file mode 100644 index 000000000..550e3ed5c --- /dev/null +++ b/gnome/CanvasPathDef.custom @@ -0,0 +1,26 @@ +// Gnome.CanvasPathDef.custom - Gnome CanvasPathDef class customizations +// +// Author: Mike Kestner +// +// Copyright (C) 2005 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + + public static CanvasPathDef NewFromBpath (Art.Bpath bpath) + { + return new CanvasPathDef (gnome_canvas_path_def_new_from_bpath (ref bpath)); + } + diff --git a/gnome/GPPath.custom b/gnome/GPPath.custom new file mode 100644 index 000000000..e3b6d4cd1 --- /dev/null +++ b/gnome/GPPath.custom @@ -0,0 +1,26 @@ +// Gnome.GPPath.custom - Gnome GPPath class customizations +// +// Author: Mike Kestner +// +// Copyright (C) 2005 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + + public static GPPath NewFromBpath (Art.Bpath bpath) + { + return new GPPath (gp_path_new_from_bpath (ref bpath)); + } + diff --git a/gnome/Makefile.am b/gnome/Makefile.am index 3464e6a50..54c395d30 100644 --- a/gnome/Makefile.am +++ b/gnome/Makefile.am @@ -29,6 +29,7 @@ customs = \ CanvasGroup.custom \ CanvasItem.custom \ CanvasLine.custom \ + CanvasPathDef.custom \ CanvasPixbuf.custom \ CanvasPoints.custom \ CanvasPolygon.custom \ diff --git a/gtk/Gtk.metadata b/gtk/Gtk.metadata index c1cc02692..d5b752e2f 100644 --- a/gtk/Gtk.metadata +++ b/gtk/Gtk.metadata @@ -114,6 +114,7 @@ 1 PackEnd PackStart + true 1 Click Press