Author: mkestner
Date: 2005-03-12 17:19:44 -0500 (Sat, 12 Mar 2005)
New Revision: 41740

Added:
   trunk/gtk-sharp/glib/WeakObject.cs
Modified:
   trunk/gtk-sharp/ChangeLog
   trunk/gtk-sharp/glib/Makefile.am
   trunk/gtk-sharp/glib/Object.cs
   trunk/gtk-sharp/gtk/Gtk.metadata
   trunk/gtk-sharp/gtk/ListStore.custom
   trunk/gtk-sharp/gtk/TreeModelSort.custom
   trunk/gtk-sharp/gtk/TreeStore.custom
Log:

2005-03-12  Mike Kestner  <[EMAIL PROTECTED]>

        * glib/Makefile.am : add new file.
        * glib/Object.cs : add protected PersistentData hash to hold data
        across GC cycles.
        * glib/WeakObject.cs : new object to hold managed refs weakly against
        the native object.
        * gtk/ListStore.custom : hold refs for DefaultSortFuncs.
        * gtk/TreeModelSort.custom : hold refs for DefaultSortFuncs.
        * gtk/TreeStore.custom : hold refs for DefaultSortFuncs.


Modified: trunk/gtk-sharp/ChangeLog
===================================================================
--- trunk/gtk-sharp/ChangeLog   2005-03-12 22:01:38 UTC (rev 41739)
+++ trunk/gtk-sharp/ChangeLog   2005-03-12 22:19:44 UTC (rev 41740)
@@ -1,5 +1,16 @@
 2005-03-12  Mike Kestner  <[EMAIL PROTECTED]>
 
+       * glib/Makefile.am : add new file.
+       * glib/Object.cs : add protected PersistentData hash to hold data
+       across GC cycles.
+       * glib/WeakObject.cs : new object to hold managed refs weakly against
+       the native object.
+       * gtk/ListStore.custom : hold refs for DefaultSortFuncs.
+       * gtk/TreeModelSort.custom : hold refs for DefaultSortFuncs.
+       * gtk/TreeStore.custom : hold refs for DefaultSortFuncs.
+
+2005-03-12  Mike Kestner  <[EMAIL PROTECTED]>
+
        * generator/CallbackGen.cs : don't derive Wrappers from DelegateWrapper
        any more.  It leaks delegates like crazy. We effectively now use call
        scope as the default for delegate parameters.

Modified: trunk/gtk-sharp/glib/Makefile.am
===================================================================
--- trunk/gtk-sharp/glib/Makefile.am    2005-03-12 22:01:38 UTC (rev 41739)
+++ trunk/gtk-sharp/glib/Makefile.am    2005-03-12 22:19:44 UTC (rev 41740)
@@ -49,7 +49,8 @@
        TypeFundamentals.cs                     \
        UnwrappedObject.cs                      \
        ValueArray.cs                           \
-       Value.cs
+       Value.cs                                \
+       WeakObject.cs
 
 build_sources = $(addprefix $(srcdir)/, $(sources)) ../AssemblyInfo.cs
 dist_sources = $(sources)

Modified: trunk/gtk-sharp/glib/Object.cs
===================================================================
--- trunk/gtk-sharp/glib/Object.cs      2005-03-12 22:01:38 UTC (rev 41739)
+++ trunk/gtk-sharp/glib/Object.cs      2005-03-12 22:19:44 UTC (rev 41740)
@@ -357,6 +357,12 @@
                        }
                }
 
+               protected Hashtable PersistentData {
+                       get {
+                               return WeakObject.Lookup (Handle).Data;
+                       }
+               }
+
                [DllImport("libgobject-2.0-0.dll")]
                static extern void g_object_get_property (IntPtr obj, IntPtr 
name, ref GLib.Value val);
 

Added: trunk/gtk-sharp/glib/WeakObject.cs
===================================================================
--- trunk/gtk-sharp/glib/WeakObject.cs  2005-03-12 22:01:38 UTC (rev 41739)
+++ trunk/gtk-sharp/glib/WeakObject.cs  2005-03-12 22:19:44 UTC (rev 41740)
@@ -0,0 +1,89 @@
+// WeakObject.cs - Object to hold managed references via native weakref.
+//
+// Authors: Mike Kestner <[EMAIL PROTECTED]>
+//
+// 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.
+
+
+namespace GLib {
+
+       using System;
+       using System.Collections;
+       using System.Runtime.InteropServices;
+
+       internal class WeakObject {
+
+               GCHandle gc_handle;
+
+               static DestroyNotify notify = new DestroyNotify 
(OnNativeDestroy);
+               delegate void DestroyNotify (IntPtr data);
+               static void OnNativeDestroy (IntPtr data)
+               {
+                       GCHandle gch = (GCHandle) data;
+                       WeakObject obj = gch.Target as WeakObject;
+                       obj.Dispose ();
+                       gch.Free ();
+               }
+
+               void Dispose ()
+               {
+                       signals = null;
+                       data = null;
+               }
+
+               WeakObject (IntPtr obj)
+               {
+                       gc_handle = GCHandle.Alloc (this);
+                       g_object_set_data_full (obj, "gtk_sharp_weak_object", 
(IntPtr) gc_handle, notify);
+               }
+
+               Hashtable data;
+               public Hashtable Data {
+                       get {
+                               if (data == null)
+                                       data = new Hashtable ();
+                               return data;
+                       }
+               }
+
+               Hashtable signals;
+               public Hashtable Signals {
+                       get {
+                               if (signals == null)
+                                       signals = new Hashtable ();
+                               return signals;
+                       }
+               }
+
+               public static WeakObject Lookup (IntPtr obj)
+               {
+                       IntPtr data = g_object_get_data (obj, 
"gtk_sharp_weak_object");
+                       if (data == IntPtr.Zero)
+                               return new WeakObject (obj);
+
+                       GCHandle gch = (GCHandle) data;
+                       return gch.Target as WeakObject;
+               }
+
+               [DllImport("libgobject-2.0-0.dll")]
+               static extern IntPtr g_object_get_data (IntPtr instance, string 
key);
+
+               [DllImport("libgobject-2.0-0.dll")]
+               static extern void g_object_set_data_full (IntPtr instance, 
string key, IntPtr data, DestroyNotify notify);
+       }
+}
+

Modified: trunk/gtk-sharp/gtk/Gtk.metadata
===================================================================
--- trunk/gtk-sharp/gtk/Gtk.metadata    2005-03-12 22:01:38 UTC (rev 41739)
+++ trunk/gtk-sharp/gtk/Gtk.metadata    2005-03-12 22:19:44 UTC (rev 41740)
@@ -93,6 +93,7 @@
   <attr path="/api/namespace/[EMAIL PROTECTED]'GtkTreeModel']/[EMAIL 
PROTECTED]'RowHasChildToggled']" name="name">EmitRowHasChildToggled</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GtkTreeModel']/[EMAIL 
PROTECTED]'RowInserted']" name="name">EmitRowInserted</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GtkTreeModel']/[EMAIL 
PROTECTED]'RowsReordered']" name="name">EmitRowsReordered</attr>
+  <attr path="/api/namespace/[EMAIL PROTECTED]'GtkTreeSortable']/[EMAIL 
PROTECTED]'SetDefaultSortFunc']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GtkTreeSortable']/[EMAIL 
PROTECTED]'SortColumnChanged']" name="name">ChangeSortColumn</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GtkAccelLabel']/[EMAIL 
PROTECTED]'gtk_accel_label_new']/*/[EMAIL PROTECTED]'string']" 
name="property_name">label</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GtkAction']/[EMAIL 
PROTECTED]'Activate']" name="name">Activated</attr>

Modified: trunk/gtk-sharp/gtk/ListStore.custom
===================================================================
--- trunk/gtk-sharp/gtk/ListStore.custom        2005-03-12 22:01:38 UTC (rev 
41739)
+++ trunk/gtk-sharp/gtk/ListStore.custom        2005-03-12 22:19:44 UTC (rev 
41740)
@@ -150,3 +150,24 @@
                        return ret;
                }
 
+               [DllImport("libgtk-win32-2.0-0.dll")]
+               static extern void 
gtk_tree_sortable_set_default_sort_func(IntPtr raw, IntPtr sort_func, IntPtr 
user_data, IntPtr destroy);
+
+               [DllImport("libgtk-win32-2.0-0.dll")]
+               static extern void 
gtk_tree_sortable_set_default_sort_func(IntPtr raw, 
GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, 
GtkSharp.DestroyNotifyNative destroy);
+
+               public void SetDefaultSortFunc (TreeIterCompareFunc sort_func, 
IntPtr user_data, Gtk.DestroyNotify destroy) 
+               {
+                       if (sort_func == null) {
+                               PersistentData ["default_sort_func"] = null;
+                               gtk_tree_sortable_set_default_sort_func 
(Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
+                               return;
+                       }
+
+                       GtkSharp.TreeIterCompareFuncWrapper sort_func_wrapper = 
new GtkSharp.TreeIterCompareFuncWrapper (sort_func);
+                       PersistentData ["default_sort_func"] = 
sort_func_wrapper;
+                       GtkSharp.DestroyNotifyWrapper destroy_wrapper = null;
+                       destroy_wrapper = new GtkSharp.DestroyNotifyWrapper 
(destroy);
+                       gtk_tree_sortable_set_default_sort_func(Handle, 
sort_func_wrapper.NativeDelegate, user_data, destroy_wrapper.NativeDelegate);
+               }
+

Modified: trunk/gtk-sharp/gtk/TreeModelSort.custom
===================================================================
--- trunk/gtk-sharp/gtk/TreeModelSort.custom    2005-03-12 22:01:38 UTC (rev 
41739)
+++ trunk/gtk-sharp/gtk/TreeModelSort.custom    2005-03-12 22:19:44 UTC (rev 
41740)
@@ -84,3 +84,25 @@
                        val.Dispose ();
                        return ret;
                }
+
+               [DllImport("libgtk-win32-2.0-0.dll")]
+               static extern void 
gtk_tree_sortable_set_default_sort_func(IntPtr raw, IntPtr sort_func, IntPtr 
user_data, IntPtr destroy);
+
+               [DllImport("libgtk-win32-2.0-0.dll")]
+               static extern void 
gtk_tree_sortable_set_default_sort_func(IntPtr raw, 
GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, 
GtkSharp.DestroyNotifyNative destroy);
+
+               public void SetDefaultSortFunc (TreeIterCompareFunc sort_func, 
IntPtr user_data, Gtk.DestroyNotify destroy) 
+               {
+                       if (sort_func == null) {
+                               PersistentData ["default_sort_func"] = null;
+                               gtk_tree_sortable_set_default_sort_func 
(Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
+                               return;
+                       }
+
+                       GtkSharp.TreeIterCompareFuncWrapper sort_func_wrapper = 
new GtkSharp.TreeIterCompareFuncWrapper (sort_func);
+                       PersistentData ["default_sort_func"] = 
sort_func_wrapper;
+                       GtkSharp.DestroyNotifyWrapper destroy_wrapper = null;
+                       destroy_wrapper = new GtkSharp.DestroyNotifyWrapper 
(destroy);
+                       gtk_tree_sortable_set_default_sort_func(Handle, 
sort_func_wrapper.NativeDelegate, user_data, destroy_wrapper.NativeDelegate);
+               }
+

Modified: trunk/gtk-sharp/gtk/TreeStore.custom
===================================================================
--- trunk/gtk-sharp/gtk/TreeStore.custom        2005-03-12 22:01:38 UTC (rev 
41739)
+++ trunk/gtk-sharp/gtk/TreeStore.custom        2005-03-12 22:19:44 UTC (rev 
41740)
@@ -193,4 +193,25 @@
                        return ret;
                }
 
+               [DllImport("libgtk-win32-2.0-0.dll")]
+               static extern void 
gtk_tree_sortable_set_default_sort_func(IntPtr raw, IntPtr sort_func, IntPtr 
user_data, IntPtr destroy);
 
+               [DllImport("libgtk-win32-2.0-0.dll")]
+               static extern void 
gtk_tree_sortable_set_default_sort_func(IntPtr raw, 
GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, 
GtkSharp.DestroyNotifyNative destroy);
+
+               public void SetDefaultSortFunc (TreeIterCompareFunc sort_func, 
IntPtr user_data, Gtk.DestroyNotify destroy) 
+               {
+                       if (sort_func == null) {
+                               PersistentData ["default_sort_func"] = null;
+                               gtk_tree_sortable_set_default_sort_func 
(Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
+                               return;
+                       }
+
+                       GtkSharp.TreeIterCompareFuncWrapper sort_func_wrapper = 
new GtkSharp.TreeIterCompareFuncWrapper (sort_func);
+                       PersistentData ["default_sort_func"] = 
sort_func_wrapper;
+                       GtkSharp.DestroyNotifyWrapper destroy_wrapper = null;
+                       destroy_wrapper = new GtkSharp.DestroyNotifyWrapper 
(destroy);
+                       gtk_tree_sortable_set_default_sort_func(Handle, 
sort_func_wrapper.NativeDelegate, user_data, destroy_wrapper.NativeDelegate);
+               }
+
+

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

Reply via email to