diff --git a/ChangeLog b/ChangeLog index 6434f5784..2557db424 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,17 @@ -2004-04-0 John Luke +2004-04-07 Mike Kestner + + * generator/ClassBase.cs : remove default ctor generation and + hasDefaultConstructor field. + * generator/Ctor.cs : chain to base (IntPtr.Zero). + * generator/StructBase.cs : remove hasDefaultConstructor usage. + * glib/Object.cs : remove Object () ctor. Add Ben's GetGType + method, although nothing uses it yet. Still working on integrating + the remainder of Ben's patch. + * gtk/Gtk.metadata : remove all the disabledefaultctor rules. + * */*.custom : add base (IntPtr.Zero) or this (...) chaining for + all ctors. + +2004-04-07 John Luke * gtk/Gtk.metadata: mark Gtk.Widget.ModifyFont font_desc null_ok diff --git a/gdk/Pixbuf.custom b/gdk/Pixbuf.custom index 3ebd85772..64fbd6b66 100644 --- a/gdk/Pixbuf.custom +++ b/gdk/Pixbuf.custom @@ -36,12 +36,12 @@ g_object_ref (Raw); } - public Pixbuf (System.IO.Stream stream) + public Pixbuf (System.IO.Stream stream) : base (IntPtr.Zero) { LoadFromStream (stream); } - public Pixbuf (System.Reflection.Assembly assembly, string resource) + public Pixbuf (System.Reflection.Assembly assembly, string resource) : base (IntPtr.Zero) { if (assembly == null) assembly = System.Reflection.Assembly.GetCallingAssembly (); @@ -93,14 +93,14 @@ } // overload to default the colorspace - public Pixbuf(byte [] data, bool has_alpha, int bits_per_sample, int width, int height, int rowstride, Gdk.PixbufDestroyNotify destroy_fn) + public Pixbuf(byte [] data, bool has_alpha, int bits_per_sample, int width, int height, int rowstride, Gdk.PixbufDestroyNotify destroy_fn) : base (IntPtr.Zero) { GdkSharp.PixbufDestroyNotifyWrapper destroy_fn_wrapper = null; destroy_fn_wrapper = new GdkSharp.PixbufDestroyNotifyWrapper (destroy_fn, this); Raw = gdk_pixbuf_new_from_data(data, (int) Gdk.Colorspace.Rgb, has_alpha, bits_per_sample, width, height, rowstride, destroy_fn_wrapper.NativeDelegate, IntPtr.Zero); } - public unsafe Pixbuf(byte[] data, bool copy_pixels) + public unsafe Pixbuf(byte[] data, bool copy_pixels) : base (IntPtr.Zero) { IntPtr error = IntPtr.Zero; Raw = gdk_pixbuf_new_from_inline(data.Length, data, copy_pixels, out error); @@ -110,7 +110,7 @@ [DllImport("libgdk_pixbuf-2.0-0.dll")] static extern unsafe IntPtr gdk_pixbuf_new_from_inline(int len, IntPtr data, bool copy_pixels, out IntPtr error); - public unsafe Pixbuf(int data_length, void *data, bool copy_pixels) + public unsafe Pixbuf(int data_length, void *data, bool copy_pixels) : base (IntPtr.Zero) { IntPtr error = IntPtr.Zero; Raw = gdk_pixbuf_new_from_inline(data_length, (IntPtr) data, copy_pixels, out error); diff --git a/generator/ClassBase.cs b/generator/ClassBase.cs index 81f9c3fc6..e1871fa12 100644 --- a/generator/ClassBase.cs +++ b/generator/ClassBase.cs @@ -4,7 +4,9 @@ // Authors: Rachel Hestilow // Mike Kestner // -// (c) 2002 Rachel Hestilow, 2001-2002 Mike Kestner +// Copyright (c) 2002 Rachel Hestilow +// Copyright (c) 2001-2003 Mike Kestner +// Copyright (c) 2004 Novell, Inc. namespace GtkSharp.Generation { using System; @@ -19,7 +21,6 @@ namespace GtkSharp.Generation { protected ArrayList interfaces = null; protected ArrayList ctors = new ArrayList(); - protected bool hasDefaultConstructor = true; private bool ctors_initted = false; private Hashtable clash_map; @@ -43,7 +44,6 @@ namespace GtkSharp.Generation { } protected ClassBase (XmlElement ns, XmlElement elem) : base (ns, elem) { - hasDefaultConstructor = !elem.HasAttribute ("disabledefaultconstructor"); foreach (XmlNode node in elem.ChildNodes) { if (!(node is XmlElement)) continue; @@ -353,12 +353,6 @@ namespace GtkSharp.Generation { foreach (Ctor ctor in ctors) ctor.Generate (gen_info); - - if (!clash_map.ContainsKey("") && hasDefaultConstructor) { - gen_info.Writer.WriteLine("\t\tprotected " + Name + "() : base(){}"); - gen_info.Writer.WriteLine(); - } - } } diff --git a/generator/Ctor.cs b/generator/Ctor.cs index 783d86445..7fd2258d7 100644 --- a/generator/Ctor.cs +++ b/generator/Ctor.cs @@ -133,7 +133,7 @@ namespace GtkSharp.Generation { sw.Write ("new {0} (", name); sw.WriteLine (cname + "(" + body.GetCallString (false) + "));"); } else { - sw.WriteLine("\t\tpublic " + safety + name + "(" + sig.ToString() + ")"); + sw.WriteLine("\t\tpublic " + safety + name + "(" + sig.ToString() + ") : base (IntPtr.Zero)"); sw.WriteLine("\t\t{"); body.Initialize(gen_info, false, false, ""); diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 0c68320d4..b80b41126 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -18,8 +18,6 @@ namespace GtkSharp.Generation { public StructBase (XmlElement ns, XmlElement elem) : base (ns, elem) { - hasDefaultConstructor = false; - foreach (XmlNode node in elem.ChildNodes) { if (!(node is XmlElement)) continue; diff --git a/glade/XML.custom b/glade/XML.custom index 7c9c38521..04a57097b 100644 --- a/glade/XML.custom +++ b/glade/XML.custom @@ -83,8 +83,11 @@ /// Creates a Glade.XML object from a Stream /// Reads the contents of the stream and parses it. It must be in /// correct Glade format - public XML (System.IO.Stream s, string root, string domain) + public XML (System.IO.Stream s, string root, string domain) : base (IntPtr.Zero) { + if (GetType() != typeof (XML)) + throw new InvalidOperationException ("Can't chain to this constructor from subclasses."); + if (s == null) throw new ArgumentNullException ("s"); @@ -99,8 +102,11 @@ /// given assembly and parses it. If the assembly is null, /// the current assembly will be used. It must be in /// correct Glade format - public XML (System.Reflection.Assembly assembly, string resource_name, string root, string domain) + public XML (System.Reflection.Assembly assembly, string resource_name, string root, string domain) : base (IntPtr.Zero) { + if (GetType() != typeof (XML)) + throw new InvalidOperationException ("Can't chain to this constructor from subclasses."); + if (assembly == null) assembly = System.Reflection.Assembly.GetCallingAssembly (); diff --git a/glib/Object.cs b/glib/Object.cs index 7a300576a..5dce8738b 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -138,10 +138,23 @@ namespace GLib { GtkSharp.ObjectManager.RegisterType (name, t.Namespace + t.Name, t.Assembly.GetName().Name); GType gtype = new GType (gtksharp_register_type (name, parent_gtype.Val)); ConnectDefaultHandlers (gtype, t); + g_types[t] = gtype; return gtype; } - protected Object () {} + + static Hashtable g_types = new Hashtable (); + public static GType GetGType (System.Type t) + { + if (g_types.ContainsKey (t)) + return (GType) g_types [t]; + + PropertyInfo pi = t.GetProperty ("GType", BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public); + if (pi != null) + return (GType) pi.GetValue (null, null); + + return RegisterGType (t); + } public Object (IntPtr raw) { diff --git a/gnome/CanvasProxy.cs b/gnome/CanvasProxy.cs index 41d54b74d..10397a872 100644 --- a/gnome/CanvasProxy.cs +++ b/gnome/CanvasProxy.cs @@ -13,14 +13,9 @@ namespace Gnome { public class CanvasProxy : Gnome.CanvasItem { - public CanvasProxy (IntPtr raw) - : base (raw) - { - } + public CanvasProxy (IntPtr raw) : base (raw) {} - protected CanvasProxy () : base () - { - } + protected CanvasProxy () : base (IntPtr.Zero) {} public event UpdateHandler Update { add { diff --git a/gnome/PrintJob.custom b/gnome/PrintJob.custom index 7b58287f7..c5ba95d96 100644 --- a/gnome/PrintJob.custom +++ b/gnome/PrintJob.custom @@ -8,7 +8,7 @@ // This code is inserted after the automatically generated code. // -public PrintJob() +public PrintJob() : base (IntPtr.Zero) { Raw = gnome_print_job_new (PrintConfig.Default().Handle); } diff --git a/gnome/Program.custom b/gnome/Program.custom index 8d5f716fa..3f9546821 100644 --- a/gnome/Program.custom +++ b/gnome/Program.custom @@ -21,8 +21,7 @@ struct PropertyArg { static extern System.IntPtr 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) +public Program (string app_id, string app_version, ModuleInfo module, string[] argv, params object[] props) : base (IntPtr.Zero) { int nargs = props.Length / 2; PropertyArg[] args = new PropertyArg[nargs]; diff --git a/gtk/Dialog.custom b/gtk/Dialog.custom index 0ecbdc0bc..a3f93893e 100644 --- a/gtk/Dialog.custom +++ b/gtk/Dialog.custom @@ -12,8 +12,10 @@ // Manually wrap until we figure out how to gen ellipses. [DllImport("libgtk-win32-2.0-0.dll")] static extern IntPtr gtk_dialog_new_with_buttons (string title, IntPtr i, int flags, IntPtr dummy); -public Dialog (string title, Gtk.Window parent, Gtk.DialogFlags flags) : base() +public Dialog (string title, Gtk.Window parent, Gtk.DialogFlags flags) : base(IntPtr.Zero) { + if (GetType() != typeof (Dialog)) + throw new InvalidOperationException ("Can't chain to this constructor from subclasses."); Raw = gtk_dialog_new_with_buttons (title, parent.Handle, (int) flags, IntPtr.Zero); } diff --git a/gtk/Frame.custom b/gtk/Frame.custom index 43bc5a88b..5b63d51c7 100644 --- a/gtk/Frame.custom +++ b/gtk/Frame.custom @@ -7,7 +7,4 @@ // // This code is inserted after the automatically generated code. // - public Frame() - { - Raw = gtk_frame_new (null); - } + public Frame() : this (null) {} diff --git a/gtk/Gtk.metadata b/gtk/Gtk.metadata index 1b21054dc..806759f4b 100644 --- a/gtk/Gtk.metadata +++ b/gtk/Gtk.metadata @@ -101,9 +101,7 @@ 1 1 1 - 1 1 - 1 1 1 1 @@ -116,7 +114,6 @@ Deselected Selected Toggled - 1 1 1 1 @@ -165,7 +162,6 @@ 1 1 out - 1 1 1 Attach @@ -242,11 +238,9 @@ 1 1 ScrollAdjustmentsSet - 1 1 1 1 - 1 ScrollAdjustmentsSet 1 1 diff --git a/gtk/Label.custom b/gtk/Label.custom index e9801900e..ba9b74b77 100644 --- a/gtk/Label.custom +++ b/gtk/Label.custom @@ -6,7 +6,4 @@ // Author: John Luke // - public Label () - { - Raw = gtk_label_new (null); - } + public Label () : this (null) {} diff --git a/gtk/ListStore.custom b/gtk/ListStore.custom index 00e0157e2..3a28cb13a 100644 --- a/gtk/ListStore.custom +++ b/gtk/ListStore.custom @@ -80,8 +80,10 @@ return AppendValues ((Array) values); } - public ListStore (params Type[] types) + public ListStore (params Type[] types) : base (IntPtr.Zero) { + if (GetType() != typeof (ListStore)) + throw new InvalidOperationException ("Can't chain to this constructor from subclasses."); IntPtr[] ctypes = new IntPtr[types.Length]; int i = 0; foreach (Type type in types) { diff --git a/gtk/NodeStore.cs b/gtk/NodeStore.cs index eeb665ff5..b33fd4dc0 100644 --- a/gtk/NodeStore.cs +++ b/gtk/NodeStore.cs @@ -270,7 +270,7 @@ namespace Gtk { [DllImport("gtksharpglue")] static extern IntPtr gtksharp_node_store_new (); - public NodeStore (Type node_type) + public NodeStore (Type node_type) : base (IntPtr.Zero) { Raw = gtksharp_node_store_new (); ScanType (node_type); diff --git a/gtk/Object.custom b/gtk/Object.custom index f6783fe02..32e23d782 100755 --- a/gtk/Object.custom +++ b/gtk/Object.custom @@ -18,6 +18,9 @@ } set { base.Raw = value; + if (value == IntPtr.Zero) + return; + if (gtksharp_object_is_floating (value)) { g_object_ref (value); Sink (); diff --git a/gtk/TreeStore.custom b/gtk/TreeStore.custom index baab86bd0..cf151957b 100644 --- a/gtk/TreeStore.custom +++ b/gtk/TreeStore.custom @@ -7,14 +7,6 @@ // This code is inserted after the automatically generated code. - /// - /// Appends a row. - /// - /// - /// - /// Appends a row to the root level of the TreeStore. - /// - [DllImport ("libgtk-win32-2.0-0.dll")] static extern void gtk_tree_store_append (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent); @@ -22,15 +14,6 @@ gtk_tree_store_append (Handle, out iter, IntPtr.Zero); } - /// - /// Inserts a row. - /// - /// - /// - /// Inserts a row in the root level of the TreeStore at - /// the given position. - /// - [DllImport ("libgtk-win32-2.0-0.dll")] static extern void gtk_tree_store_insert (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent, int position); @@ -38,14 +21,6 @@ gtk_tree_store_insert (Handle, out iter, IntPtr.Zero, position); } - /// - /// Prepends a row. - /// - /// - /// - /// Prepends a row to the root level of the TreeStore. - /// - [DllImport ("libgtk-win32-2.0-0.dll")] static extern void gtk_tree_store_prepend (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent); @@ -53,15 +28,6 @@ gtk_tree_store_append (Handle, out iter, IntPtr.Zero); } - /// - /// Inserts a row. - /// - /// - /// - /// Inserts a row in the root level of TreeStore before the - /// given sibling. - /// - [DllImport ("libgtk-win32-2.0-0.dll")] static extern void gtk_tree_store_insert_before (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent, ref Gtk.TreeIter sibling); @@ -69,15 +35,6 @@ gtk_tree_store_insert_before (Handle, out iter, IntPtr.Zero, ref sibling); } - /// - /// Inserts a row. - /// - /// - /// - /// Inserts a row in the root level of TreeStore before the - /// given sibling. - /// - [DllImport ("libgtk-win32-2.0-0.dll")] static extern void gtk_tree_store_insert_after (IntPtr raw, out Gtk.TreeIter iter, IntPtr parent, ref Gtk.TreeIter sibling); @@ -168,8 +125,11 @@ return AppendValues ((Array) values); } - public TreeStore (params Type[] types) + public TreeStore (params Type[] types) : base (IntPtr.Zero) { + if (GetType() != typeof (TreeStore)) + throw new InvalidOperationException ("Can't chain to this constructor from subclasses."); + IntPtr[] ctypes = new IntPtr[types.Length]; int i = 0; foreach (Type type in types) { diff --git a/gtk/TreeView.custom b/gtk/TreeView.custom index c2ded12a1..94a859a0d 100644 --- a/gtk/TreeView.custom +++ b/gtk/TreeView.custom @@ -10,8 +10,10 @@ // This code is inserted after the automatically generated code. - public TreeView (NodeStore store) + public TreeView (NodeStore store) : base (IntPtr.Zero) { + if (GetType() != typeof (TreeView)) + throw new InvalidOperationException ("Can't chain to this constructor from subclasses."); Raw = gtk_tree_view_new_with_model (store.Handle); } diff --git a/gtk/TreeViewColumn.custom b/gtk/TreeViewColumn.custom index 16a24acf0..df6727262 100644 --- a/gtk/TreeViewColumn.custom +++ b/gtk/TreeViewColumn.custom @@ -21,14 +21,13 @@ } } - public TreeViewColumn (string title, Gtk.CellRenderer cell, Array attrs) { - Raw = gtk_tree_view_column_new (); + public TreeViewColumn (string title, Gtk.CellRenderer cell, Array attrs) : this () + { _NewWithAttributes (title, cell, attrs); } - public TreeViewColumn (string title, Gtk.CellRenderer cell, params object[] attrs) + public TreeViewColumn (string title, Gtk.CellRenderer cell, params object[] attrs) : this () { - Raw = gtk_tree_view_column_new (); _NewWithAttributes (title, cell, attrs); } diff --git a/gtk/Window.custom b/gtk/Window.custom index 338a12b74..84b039b20 100755 --- a/gtk/Window.custom +++ b/gtk/Window.custom @@ -17,6 +17,8 @@ } set { base.Raw = value; + if (value == IntPtr.Zero) + return; g_object_ref (value); } }