* glib/Object.cs (CreateNativeObject): virtualize

(Object(GType)): Mark this ctor Obsolete

	* gtk/Gtk.metadata: disable the generated GType ctor on Gtk.Widget

	* gtk/Widget.custom (Widget, CreateNativeObject,
	Widget_ParentSet): Connect to our own ParentSet event from
	CreateNativeObject and the GType ctor, and keep a static Hashtable
	of parented widgets, so that adding a managed widget to a
	container keeps both the GObject and the managed object alive.

	* generator/ObjectGen.cs (GenCtors): handle the disable_gtype_ctor
	flag. Also, mark GType ctors [Obsolete]

svn path=/trunk/gtk-sharp/; revision=35885
This commit is contained in:
Dan Winship 2004-11-09 14:22:39 +00:00
parent 9084ce3133
commit e1dc10e4c8
5 changed files with 48 additions and 3 deletions

View File

@ -1,5 +1,18 @@
2004-11-08 Dan Winship <danw@novell.com>
* glib/Object.cs (CreateNativeObject): virtualize
* gtk/Gtk.metadata: disable the generated GType ctor on Gtk.Widget
* gtk/Widget.custom (Widget, CreateNativeObject,
Widget_ParentSet): Connect to our own ParentSet event from
CreateNativeObject and the GType ctor, and keep a static Hashtable
of parented widgets, so that adding a managed widget to a
container keeps both the GObject and the managed object alive.
* generator/ObjectGen.cs (GenCtors): handle the disable_gtype_ctor
flag. Also, mark GType ctors [Obsolete]
* generator/ChildProperty.cs:
* generator/Property.cs: Fix child property names.

View File

@ -69,6 +69,12 @@ namespace GtkSharp.Generation {
}
}
private bool DisableGTypeCtor {
get {
return Elem.HasAttribute ("disable_gtype_ctor");
}
}
private class DirectoryInfo {
public string assembly_name;
public Hashtable objects;
@ -223,7 +229,10 @@ namespace GtkSharp.Generation {
gen_info.Writer.WriteLine("\t\t\tDispose();");
gen_info.Writer.WriteLine("\t\t}");
gen_info.Writer.WriteLine();
gen_info.Writer.WriteLine("\t\tprotected " + Name + "(GLib.GType gtype) : base(gtype) {}");
if (!DisableGTypeCtor) {
gen_info.Writer.WriteLine("\t\t[Obsolete]");
gen_info.Writer.WriteLine("\t\tprotected " + Name + "(GLib.GType gtype) : base(gtype) {}");
}
gen_info.Writer.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}");
if (ctors.Count == 0 && !DisableVoidCtor) {
gen_info.Writer.WriteLine();

View File

@ -179,6 +179,7 @@ namespace GLib {
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_object_new (IntPtr gtype, IntPtr dummy);
[Obsolete]
protected Object (GType gtype)
{
Raw = g_object_new (gtype.Val, IntPtr.Zero);
@ -187,7 +188,7 @@ namespace GLib {
[DllImport("glibsharpglue-2.0")]
static extern IntPtr gtksharp_object_newv (IntPtr gtype, int n_params, string[] names, GLib.Value[] vals);
protected void CreateNativeObject (string[] names, GLib.Value[] vals)
protected virtual void CreateNativeObject (string[] names, GLib.Value[] vals)
{
Raw = gtksharp_object_newv (LookupGType ().Val, names.Length, names, vals);
}

View File

@ -336,6 +336,7 @@
<attr path="/api/namespace/object[@cname='GtkVScale']/constructor[@cname='gtk_vscale_new']/*/*[@type='GtkAdjustment*']" name="null_ok">1</attr>
<attr path="/api/namespace/object[@cname='GtkVScale']/constructor[@cname='gtk_vscale_new_with_range']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkVScrollbar']/constructor[@cname='gtk_vscrollbar_new']/*/*[@type='GtkAdjustment*']" name="null_ok">1</attr>
<attr path="/api/namespace/object[@cname='GtkWidget']" name="disable_gtype_ctor">1</attr>
<attr path="/api/namespace/object[@cname='GtkWidget']/constructor[@cname='gtk_widget_new']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkWidget']/method[@name='ClassPath']/*/*[@type='gchar**']" name="pass_as">out</attr>
<attr path="/api/namespace/object[@cname='GtkWidget']/method[@name='Destroyed']" name="hidden">1</attr>

View File

@ -22,7 +22,28 @@
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
[Obsolete]
protected Widget (GLib.GType gtype) : base(gtype)
{
ParentSet += new ParentSetHandler (Widget_ParentSet);
}
protected override void CreateNativeObject (string[] names, GLib.Value[] vals)
{
base.CreateNativeObject (names, vals);
ParentSet += new ParentSetHandler (Widget_ParentSet);
}
private static Hashtable ParentedWidgets = new Hashtable ();
private void Widget_ParentSet (object o, ParentSetArgs args)
{
if (Parent != null && args.PreviousParent == null)
ParentedWidgets[this] = this;
else if (Parent == null && args.PreviousParent != null)
ParentedWidgets.Remove (this);
}
[DllImport("gtksharpglue-2.0")]
static extern IntPtr gtksharp_gtk_widget_get_allocation (IntPtr style);