Author: mkestner
Date: 2005-05-11 09:12:09 -0400 (Wed, 11 May 2005)
New Revision: 44388

Modified:
   trunk/gtk-sharp/ChangeLog
   trunk/gtk-sharp/gtk/Object.custom
   trunk/gtk-sharp/gtk/Widget.custom
Log:

2005-05-10  Mike Kestner  <[EMAIL PROTECTED]>

        * 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.


Modified: trunk/gtk-sharp/ChangeLog
===================================================================
--- trunk/gtk-sharp/ChangeLog   2005-05-11 12:38:50 UTC (rev 44387)
+++ trunk/gtk-sharp/ChangeLog   2005-05-11 13:12:09 UTC (rev 44388)
@@ -1,5 +1,12 @@
 2005-05-10  Mike Kestner  <[EMAIL PROTECTED]>
 
+       * 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  <[EMAIL PROTECTED]>
+
        * gdk/Pixbuf.custom : use non-obsolete PixbufLoader.Write overload.
        * gdk/PixbufLoader.custom : add obsolete PixbufLoader.Write overload
        for the uint case for backcompat. Update other uses to the new ulong

Modified: trunk/gtk-sharp/gtk/Object.custom
===================================================================
--- trunk/gtk-sharp/gtk/Object.custom   2005-05-11 12:38:50 UTC (rev 44387)
+++ trunk/gtk-sharp/gtk/Object.custom   2005-05-11 13:12:09 UTC (rev 44388)
@@ -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 {

Modified: trunk/gtk-sharp/gtk/Widget.custom
===================================================================
--- trunk/gtk-sharp/gtk/Widget.custom   2005-05-11 12:38:50 UTC (rev 44387)
+++ trunk/gtk-sharp/gtk/Widget.custom   2005-05-11 13:12:09 UTC (rev 44388)
@@ -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 @@
 
 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)
+       Widget w = GLib.Object.GetObject (raw) as Widget;
+       if (w.Parent == null)
+               ParentedWidgets.Remove (w);
+       else
                ParentedWidgets[w] = w;
-       else if (w.Parent == null && args.PreviousParent != null)
-               ParentedWidgets.Remove (w);
+       Console.WriteLine ("Parenting " + w + " at " + raw);
 }
 
 [DllImport("gtksharpglue-2")]

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to