2005-05-10 Mike Kestner <mkestner@novell.com>

* gtk/Object.custom : Dispose on a Destroyed event.
	* gtk/Widget.custom : rework the parent_set hack to go direct to
	the native signal instead of using the event so we avoid rewrapping of
	already destroyed parents.

svn path=/trunk/gtk-sharp/; revision=44388
This commit is contained in:
Mike Kestner 2005-05-11 13:12:09 +00:00
parent a51e811f17
commit c1564a1288
3 changed files with 54 additions and 8 deletions

View file

@ -1,3 +1,10 @@
2005-05-10 Mike Kestner <mkestner@novell.com>
* gtk/Object.custom : Dispose on a Destroyed event.
* gtk/Widget.custom : rework the parent_set hack to go direct to
the native signal instead of using the event so we avoid rewrapping of
already destroyed parents.
2005-05-10 Mike Kestner <mkestner@novell.com>
* gdk/Pixbuf.custom : use non-obsolete PixbufLoader.Write overload.

View file

@ -30,6 +30,23 @@
[DllImport("libgobject-2.0-0.dll")]
private static extern void g_object_ref (IntPtr raw);
static void NativeDestroy (object o, EventArgs args)
{
GLib.Object obj = o as GLib.Object;
if (obj == null)
return;
obj.Dispose ();
}
static EventHandler native_destroy_handler;
static EventHandler NativeDestroyHandler {
get {
if (native_destroy_handler == null)
native_destroy_handler = new EventHandler (NativeDestroy);
return native_destroy_handler;
}
}
protected override IntPtr Raw {
get {
return base.Raw;
@ -41,6 +58,7 @@
g_object_ref (value);
Sink ();
Destroyed += NativeDestroyHandler;
}
}
@ -49,7 +67,9 @@
public virtual void Destroy ()
{
Destroyed -= NativeDestroyHandler;
gtk_object_destroy (Handle);
Dispose ();
}
public bool IsFloating {

View file

@ -25,7 +25,9 @@
[Obsolete]
protected Widget (GLib.GType gtype) : base(gtype)
{
ParentSet += new ParentSetHandler (Widget_ParentSet);
IntPtr name = GLib.Marshaller.StringToPtrGStrdup ("parent-set");
g_signal_connect_data (Handle, name, NativeParentSetHandler, IntPtr.Zero, IntPtr.Zero, 0);
GLib.Marshaller.Free (name);
}
[DllImport("libgtk-win32-2.0-0.dll")]
@ -33,24 +35,41 @@ static extern void gtk_widget_destroy (IntPtr raw);
public override void Destroy ()
{
gtk_widget_destroy (Handle);
base.Destroy ();
}
delegate void NativeParentSetDelegate (IntPtr obj, IntPtr prev, IntPtr data);
[DllImport("libgobject-2.0-0.dll")]
static extern int g_signal_connect_data (IntPtr raw, IntPtr name, NativeParentSetDelegate hndlr, IntPtr data, IntPtr notify, int flags);
protected override void CreateNativeObject (string[] names, GLib.Value[] vals)
{
base.CreateNativeObject (names, vals);
ParentSet += new ParentSetHandler (Widget_ParentSet);
IntPtr name = GLib.Marshaller.StringToPtrGStrdup ("parent-set");
g_signal_connect_data (Handle, name, NativeParentSetHandler, IntPtr.Zero, IntPtr.Zero, 0);
GLib.Marshaller.Free (name);
}
private static Hashtable ParentedWidgets = new Hashtable ();
private static void Widget_ParentSet (object o, ParentSetArgs args)
private static NativeParentSetDelegate native_parent_set_handler;
private static NativeParentSetDelegate NativeParentSetHandler {
get {
if (native_parent_set_handler == null)
native_parent_set_handler = new NativeParentSetDelegate (Widget_ParentSet);
return native_parent_set_handler;
}
}
private static void Widget_ParentSet (IntPtr raw, IntPtr prev, IntPtr data)
{
Widget w = o as Widget;
if (w.Parent != null && args.PreviousParent == null)
ParentedWidgets[w] = w;
else if (w.Parent == null && args.PreviousParent != null)
Widget w = GLib.Object.GetObject (raw) as Widget;
if (w.Parent == null)
ParentedWidgets.Remove (w);
else
ParentedWidgets[w] = w;
Console.WriteLine ("Parenting " + w + " at " + raw);
}
[DllImport("gtksharpglue-2")]