From 23ec73d6f97be98a062cef6ce4123e2e6c9453f8 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Tue, 5 Apr 2005 14:48:49 +0000 Subject: [PATCH] 2005-04-05 Mike Kestner * gtk/DestroyHelper.cs : implement an internal DestroyNotify handler to release GCHandles. * gtk/*.custom : rework existing persistent delegate implementations to use destroy notify or PersistentData. svn path=/trunk/gtk-sharp/; revision=42571 --- ChangeLog | 7 ++++ doc/en/Gtk/ListStore.xml | 75 +++++++++++++++++++++++++----------- doc/en/Gtk/TreeModelSort.xml | 48 +++++++++++++++++++---- doc/en/Gtk/TreeSortable.xml | 48 +++++++++++++++++++---- doc/en/Gtk/TreeStore.xml | 44 ++++++++++++++++++--- gtk/Accel.custom | 6 +-- gtk/CellView.custom | 27 ++++--------- gtk/ComboBox.custom | 27 ++++--------- gtk/DestroyHelper.cs | 51 ++++++++++++++++++++++++ gtk/EntryCompletion.custom | 27 ++++--------- gtk/Gtk.metadata | 1 + gtk/ListStore.custom | 56 +++++++++++++-------------- gtk/Makefile.am | 1 + gtk/Toolbar.custom | 21 ++++------ gtk/TreeModelFilter.custom | 36 +++++------------ gtk/TreeModelSort.custom | 62 ++++++++++++++--------------- gtk/TreeSortable.custom | 6 +++ gtk/TreeStore.custom | 62 ++++++++++++++--------------- gtk/TreeViewColumn.custom | 72 +++++++++++++++------------------- 19 files changed, 397 insertions(+), 280 deletions(-) create mode 100644 gtk/DestroyHelper.cs diff --git a/ChangeLog b/ChangeLog index 7ba3be5c3..115c78206 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-04-05 Mike Kestner + + * gtk/DestroyHelper.cs : implement an internal DestroyNotify handler + to release GCHandles. + * gtk/*.custom : rework existing persistent delegate implementations + to use destroy notify or PersistentData. + 2005-04-05 Alp Toker * gtk/Menu.custom: don't re-implement the Screen getter in Gtk.Menu. diff --git a/doc/en/Gtk/ListStore.xml b/doc/en/Gtk/ListStore.xml index a4c284058..ea1988789 100644 --- a/doc/en/Gtk/ListStore.xml +++ b/doc/en/Gtk/ListStore.xml @@ -51,10 +51,10 @@ - Returns the number of children that has. + Returns the number of children that has. - an object of type , the number of children of . - As a special case, if is , then the number + an object of type , the number of children of . + As a special case, if is , then the number of toplevel nodes is returned. @@ -69,22 +69,21 @@ - Sets to point to the first child of . + Sets to point to the first child of . an object of type an object of type , - , if has been set to the first child. + , if has been set to the first child. - - If has no children, - is returned and is set to be invalid. will remain a valid + + If has no children, + is returned and is set to be invalid. will remain a valid node after this function has been called. - - If is returns the first node, equivalent to - gtk_tree_model_get_iter_first (tree_model, iter); - - + + If is returns the first node, equivalent to + gtk_tree_model_get_iter_first (tree_model, iter); + @@ -129,13 +128,12 @@ - Sets a sort function to be used for the column - . + Sets a sort function to be used for the column . A for the column number. A - A - A , function that will be run on destruction of - + ignored + ignored + This overload is obsolete. The two parameter overload is preferred for new code. @@ -152,9 +150,9 @@ Set the function that will be used by default to sort columns. A - A (FIXME: explain this) - A , function that will be run on destruction of - + ignored + ignored + This overload is obsolete. The single parameter overload is preferred for new code. @@ -1432,7 +1430,40 @@ The above example creates a new three columns list store. The types of the colum Protected constructor. a - + + + + + + + Method + + System.Void + + + + + + + Sets a sort function to be used for the column . + A for the column number. + A + + + + + + Method + + System.Void + + + + + + Set the function that will be used by default to sort columns. + A + diff --git a/doc/en/Gtk/TreeModelSort.xml b/doc/en/Gtk/TreeModelSort.xml index cc2f82404..c1352a2a8 100644 --- a/doc/en/Gtk/TreeModelSort.xml +++ b/doc/en/Gtk/TreeModelSort.xml @@ -107,12 +107,12 @@ node is always the parent. - Sets a function that should be used to be sort a particular column. + Sets a function to sort a particular column. A , the index of the column to be sorted A , the function to use for sorting - An , pointer to the user data, or - A to be called when user data is destroyed, or . - This method is meant to be used together with .(FIXME: explain the user data parameter.) + ignored + ignored + This overload is obsolete. The two parameter overload is preferred for new code. @@ -129,9 +129,9 @@ node is always the parent. Sets a function that should be used to be sort columns by default if not otherwise specified by . A , the function to use for sorting - An , pointer to the user data, or - A to be called when user data is destroyed, or . - This method is meant to be used together with .(FIXME: explain the user data parameter.) + ignored + ignored + This overload is obsolete. The single parameter overload is preferred for new code. @@ -1156,5 +1156,37 @@ node is always the parent. + + + Method + + System.Void + + + + + + + Sets a function to sort a particular column. + A , the index of the column to be sorted + A , the function to use for sorting + This method is meant to be used together with . + + + + + Method + + System.Void + + + + + + Sets a function to sort columns by default if not otherwise specified by . + A , the function to use for sorting + This method is meant to be used together with . + + - \ No newline at end of file + diff --git a/doc/en/Gtk/TreeSortable.xml b/doc/en/Gtk/TreeSortable.xml index 95a0eb05c..2d445260f 100644 --- a/doc/en/Gtk/TreeSortable.xml +++ b/doc/en/Gtk/TreeSortable.xml @@ -66,9 +66,9 @@ Sets a function that should be used to be sort a particular column. A , the index of the column to be sorted A , the function to use for sorting - An , pointer to the user data, or - A to be called when user data is destroyed, or . - This method is meant to be used together with .(FIXME: explain the user data parameter.) + ignored + ignored + This overloaded method is obsolete. It is replaced by the SetSortFunc (int, TreeIterCompareFunc) overload." />. @@ -83,11 +83,11 @@ - Sets a function that should be used to be sort columns by default if not otherwise specified by . + Sets a function to sort columns by default if not otherwise specified by . A , the function to use for sorting - An , pointer to the user data, or - A to be called when user data is destroyed, or . - This method is meant to be used together with .(FIXME: explain the user data parameter.) + ignored + ignored + This overload of SetDefaultSortFunc is obsolete. The replacement is a single parameter overload. The and paramaters to this method are ignored. @@ -133,5 +133,37 @@ See to set a default sort function. + + + Method + + System.Void + + + + + + Sets a function to sort columns by default if not otherwise specified by . + A , the function to use for sorting + This method is meant to be used together with + + + + + Method + + System.Void + + + + + + + Sets a function that should be used to be sort a particular column. + A , the index of the column to be sorted + A , the function to use for sorting + This method is meant to be used together with + + - \ No newline at end of file + diff --git a/doc/en/Gtk/TreeStore.xml b/doc/en/Gtk/TreeStore.xml index 2e37c1117..5bc7f5e3f 100644 --- a/doc/en/Gtk/TreeStore.xml +++ b/doc/en/Gtk/TreeStore.xml @@ -149,9 +149,9 @@ Sets a function that should be used to be sort a particular column. A , the index of the column to be sorted A , the function to use for sorting - An , pointer to the user data, or - A to be called when user data is destroyed, or . - This method is meant to be used together with .(FIXME: explain the user data parameter.) + ignored + ignored + This overload is obsolete. The two parameter is preferred for new code. @@ -168,9 +168,9 @@ Sets a function that should be used to be sort columns by default if not otherwise specified by . A , the function to use for sorting - An , pointer to the user data, or - A to be called when user data is destroyed, or . - This method is meant to be used together with .(FIXME: explain the user data parameter.) + ignored + ignored + This overload is obsolete. The single parameter overload is preferred for new code. @@ -1744,5 +1744,37 @@ store = new TreeStore (typeof (int), typeof (string)); + + + Method + + System.Void + + + + + + + Sets a function that should be used to be sort a particular column. + A , the index of the column to be sorted + A , the function to use for sorting + This method is meant to be used together with + + + + + Method + + System.Void + + + + + + Sets a function that should be used to be sort columns by default if not otherwise specified by . + A , the function to use for sorting + This method is meant to be used together with . + + diff --git a/gtk/Accel.custom b/gtk/Accel.custom index 44482bea2..ebeee247d 100644 --- a/gtk/Accel.custom +++ b/gtk/Accel.custom @@ -43,8 +43,7 @@ [Obsolete("Moved to AccelMap class. Use AccelMap.ForeachUnfiltered instead")] public static void MapForeachUnfiltered(IntPtr data, Gtk.AccelMapForeach foreach_func) { - GtkSharp.AccelMapForeachWrapper foreach_func_wrapper = null; - foreach_func_wrapper = new GtkSharp.AccelMapForeachWrapper (foreach_func); + GtkSharp.AccelMapForeachWrapper foreach_func_wrapper = new GtkSharp.AccelMapForeachWrapper (foreach_func); gtk_accel_map_foreach_unfiltered(data, foreach_func_wrapper.NativeDelegate); } @@ -111,8 +110,7 @@ [Obsolete("Moved to AccelMap class. Use AccelMap.Foreach instead")] public static void MapForeach(IntPtr data, Gtk.AccelMapForeach foreach_func) { - GtkSharp.AccelMapForeachWrapper foreach_func_wrapper = null; - foreach_func_wrapper = new GtkSharp.AccelMapForeachWrapper (foreach_func); + GtkSharp.AccelMapForeachWrapper foreach_func_wrapper = new GtkSharp.AccelMapForeachWrapper (foreach_func); gtk_accel_map_foreach(data, foreach_func_wrapper.NativeDelegate); } diff --git a/gtk/CellView.custom b/gtk/CellView.custom index edaef28f5..b36261414 100644 --- a/gtk/CellView.custom +++ b/gtk/CellView.custom @@ -21,15 +21,6 @@ // Boston, MA 02111-1307, USA. - Hashtable datafuncs; - Hashtable DataFuncs { - get { - if (datafuncs == null) - datafuncs = new Hashtable (); - return datafuncs; - } - } - public void SetAttributes (CellRenderer cell, params object[] attrs) { if (attrs.Length % 2 != 0) @@ -42,21 +33,17 @@ } [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_cell_layout_set_cell_data_func(IntPtr raw, IntPtr cell_renderer, IntPtr func, IntPtr func_data, IntPtr destroy); - - [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_cell_layout_set_cell_data_func(IntPtr raw, IntPtr cell_renderer, GtkSharp.CellLayoutDataFuncNative func, IntPtr func_data, IntPtr destroy); + static extern void gtk_cell_layout_set_cell_data_func(IntPtr raw, IntPtr cell_renderer, GtkSharp.CellLayoutDataFuncNative func, IntPtr func_data, NativeDestroyNotify destroy); public void SetCellDataFunc (CellRenderer renderer, CellLayoutDataFunc func) { if (func == null) { - DataFuncs [renderer] = null; - gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); - } else { - - GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func); - DataFuncs [renderer] = func_wrapper; - gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, func_wrapper.NativeDelegate, IntPtr.Zero, IntPtr.Zero); + gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, null, IntPtr.Zero, null); + return; } + + GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func); + GCHandle gch = GCHandle.Alloc (func_wrapper); + gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); } diff --git a/gtk/ComboBox.custom b/gtk/ComboBox.custom index c366d0029..f8ee6f483 100644 --- a/gtk/ComboBox.custom +++ b/gtk/ComboBox.custom @@ -21,15 +21,6 @@ // Boston, MA 02111-1307, USA. - Hashtable datafuncs; - Hashtable DataFuncs { - get { - if (datafuncs == null) - datafuncs = new Hashtable (); - return datafuncs; - } - } - public void SetAttributes (CellRenderer cell, params object[] attrs) { if (attrs.Length % 2 != 0) @@ -42,21 +33,17 @@ } [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_cell_layout_set_cell_data_func(IntPtr raw, IntPtr cell_renderer, IntPtr func, IntPtr func_data, IntPtr destroy); - - [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_cell_layout_set_cell_data_func(IntPtr raw, IntPtr cell_renderer, GtkSharp.CellLayoutDataFuncNative func, IntPtr func_data, IntPtr destroy); + static extern void gtk_cell_layout_set_cell_data_func(IntPtr raw, IntPtr cell_renderer, GtkSharp.CellLayoutDataFuncNative func, IntPtr func_data, NativeDestroyNotify destroy); public void SetCellDataFunc (CellRenderer renderer, CellLayoutDataFunc func) { if (func == null) { - DataFuncs [renderer] = null; - gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); - } else { - - GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func); - DataFuncs [renderer] = func_wrapper; - gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, func_wrapper.NativeDelegate, IntPtr.Zero, IntPtr.Zero); + gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, null, IntPtr.Zero, null); + return; } + + GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func); + GCHandle gch = GCHandle.Alloc (func_wrapper); + gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); } diff --git a/gtk/DestroyHelper.cs b/gtk/DestroyHelper.cs new file mode 100644 index 000000000..3c8a385fc --- /dev/null +++ b/gtk/DestroyHelper.cs @@ -0,0 +1,51 @@ +// Gtk.DestroyHelper.cs - internal DestroyNotify helper +// +// Author: Mike Kestner +// +// 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 Gtk { + + using System; + using System.Runtime.InteropServices; + + internal delegate void NativeDestroyNotify (IntPtr data); + + internal class DestroyHelper { + + private DestroyHelper () {} + + static void ReleaseGCHandle (IntPtr data) + { + if (data == IntPtr.Zero) + return; + GCHandle gch = (GCHandle) data; + gch.Free (); + } + + static NativeDestroyNotify release_gchandle; + + internal static NativeDestroyNotify NotifyHandler { + get { + if (release_gchandle == null) + release_gchandle = new NativeDestroyNotify (ReleaseGCHandle); + return release_gchandle; + } + } + } +} + diff --git a/gtk/EntryCompletion.custom b/gtk/EntryCompletion.custom index 29ad95253..ca4121446 100644 --- a/gtk/EntryCompletion.custom +++ b/gtk/EntryCompletion.custom @@ -21,15 +21,6 @@ // Boston, MA 02111-1307, USA. - Hashtable datafuncs; - Hashtable DataFuncs { - get { - if (datafuncs == null) - datafuncs = new Hashtable (); - return datafuncs; - } - } - public void SetAttributes (CellRenderer cell, params object[] attrs) { if (attrs.Length % 2 != 0) @@ -42,21 +33,17 @@ } [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_cell_layout_set_cell_data_func(IntPtr raw, IntPtr cell_renderer, IntPtr func, IntPtr func_data, IntPtr destroy); - - [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_cell_layout_set_cell_data_func(IntPtr raw, IntPtr cell_renderer, GtkSharp.CellLayoutDataFuncNative func, IntPtr func_data, IntPtr destroy); + static extern void gtk_cell_layout_set_cell_data_func(IntPtr raw, IntPtr cell_renderer, GtkSharp.CellLayoutDataFuncNative func, IntPtr func_data, NativeDestroyNotify destroy); public void SetCellDataFunc (CellRenderer renderer, CellLayoutDataFunc func) { if (func == null) { - DataFuncs [renderer] = null; - gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); - } else { - - GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func); - DataFuncs [renderer] = func_wrapper; - gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, func_wrapper.NativeDelegate, IntPtr.Zero, IntPtr.Zero); + gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, null, IntPtr.Zero, null); + return; } + + GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func); + GCHandle gch = GCHandle.Alloc (func_wrapper); + gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); } diff --git a/gtk/Gtk.metadata b/gtk/Gtk.metadata index d0f34c763..26bf89d59 100644 --- a/gtk/Gtk.metadata +++ b/gtk/Gtk.metadata @@ -377,6 +377,7 @@ 1 1 1 + 1 1 1 out diff --git a/gtk/ListStore.custom b/gtk/ListStore.custom index 3eab3b6ec..5fd14bdab 100644 --- a/gtk/ListStore.custom +++ b/gtk/ListStore.custom @@ -151,44 +151,44 @@ } [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_tree_sortable_set_sort_func(IntPtr raw, int col_id, IntPtr sort_func, IntPtr user_data, IntPtr destroy); - - [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_tree_sortable_set_sort_func(IntPtr raw, int col_id, GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, GtkSharp.DestroyNotifyNative destroy); + static extern void gtk_tree_sortable_set_sort_func(IntPtr raw, int col_id, GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, NativeDestroyNotify destroy); + [Obsolete ("Replaced by SetSortFunc (int, TreeIterCompareFunc) overload.")] public void SetSortFunc (int sort_column_id, TreeIterCompareFunc sort_func, IntPtr user_data, Gtk.DestroyNotify destroy) { - if (sort_func == null) { - PersistentData ["column_" + sort_column_id + "_sort_func"] = null; - gtk_tree_sortable_set_sort_func (Handle, sort_column_id, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); - return; - } - - GtkSharp.TreeIterCompareFuncWrapper sort_func_wrapper = new GtkSharp.TreeIterCompareFuncWrapper (sort_func); - PersistentData ["column_" + sort_column_id + "_sort_func"] = sort_func_wrapper; - GtkSharp.DestroyNotifyWrapper destroy_wrapper = null; - destroy_wrapper = new GtkSharp.DestroyNotifyWrapper (destroy); - gtk_tree_sortable_set_sort_func(Handle, sort_column_id, sort_func_wrapper.NativeDelegate, user_data, destroy_wrapper.NativeDelegate); + SetSortFunc (sort_column_id, sort_func); } - [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) + public void SetSortFunc (int sort_column_id, TreeIterCompareFunc sort_func) { if (sort_func == null) { - PersistentData ["default_sort_func"] = null; - gtk_tree_sortable_set_default_sort_func (Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); + gtk_tree_sortable_set_sort_func (Handle, sort_column_id, null, IntPtr.Zero, null); 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); + GCHandle gch = GCHandle.Alloc (sort_func_wrapper); + gtk_tree_sortable_set_sort_func(Handle, sort_column_id, sort_func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); + } + + [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, NativeDestroyNotify destroy); + + [Obsolete ("Replaced by SetDefaultSortFunc (TreeIterCompareFunc) overload.")] + public void SetDefaultSortFunc (TreeIterCompareFunc sort_func, IntPtr user_data, Gtk.DestroyNotify destroy) + { + SetDefaultSortFunc (sort_func); + } + + public void SetDefaultSortFunc (TreeIterCompareFunc sort_func) + { + if (sort_func == null) { + gtk_tree_sortable_set_default_sort_func (Handle, null, IntPtr.Zero, null); + return; + } + + GtkSharp.TreeIterCompareFuncWrapper sort_func_wrapper = new GtkSharp.TreeIterCompareFuncWrapper (sort_func); + GCHandle gch = GCHandle.Alloc (sort_func_wrapper); + gtk_tree_sortable_set_default_sort_func(Handle, sort_func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); } diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 28a7e2733..9f8a295f0 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -14,6 +14,7 @@ sources = \ Application.cs \ BindingAttribute.cs \ ChildPropertyAttribute.cs \ + DestroyHelper.cs \ ITreeNode.cs \ NodeCellDataFunc.cs \ NodeSelection.cs \ diff --git a/gtk/Toolbar.custom b/gtk/Toolbar.custom index 4e0d06fd3..67bdcc497 100644 --- a/gtk/Toolbar.custom +++ b/gtk/Toolbar.custom @@ -46,8 +46,7 @@ [Obsolete ("Replaced by ToolItem API")] public Gtk.Widget AppendElement (Gtk.ToolbarChildType type, Gtk.Widget widget, string text, string tooltip_text, string tooltip_private_text, Gtk.Widget icon, Gtk.SignalFunc cb) { - GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); + GtkSharp.SignalFuncWrapper cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr ntext = GLib.Marshaller.StringToPtrGStrdup (text); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); @@ -71,8 +70,7 @@ [Obsolete ("Replaced by ToolItem API")] public Gtk.Widget InsertElement (Gtk.ToolbarChildType type, Gtk.Widget widget, string text, string tooltip_text, string tooltip_private_text, Gtk.Widget icon, Gtk.SignalFunc cb, IntPtr user_data, int position) { - GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); + GtkSharp.SignalFuncWrapper cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr ntext = GLib.Marshaller.StringToPtrGStrdup (text); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); @@ -97,8 +95,7 @@ [Obsolete ("Replaced by ToolItem API")] public Gtk.Widget PrependElement (Gtk.ToolbarChildType type, Gtk.Widget widget, string text, string tooltip_text, string tooltip_private_text, Gtk.Widget icon, Gtk.SignalFunc cb) { - GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); + GtkSharp.SignalFuncWrapper cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr ntext = GLib.Marshaller.StringToPtrGStrdup (text); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); @@ -122,8 +119,7 @@ [Obsolete ("Replaced by ToolItem API")] public Gtk.Widget AppendItem (string text, string tooltip_text, string tooltip_private_text, Gtk.Widget icon, Gtk.SignalFunc cb) { - GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); + GtkSharp.SignalFuncWrapper cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr ntext = GLib.Marshaller.StringToPtrGStrdup (text); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); @@ -147,8 +143,7 @@ [Obsolete ("Replaced by ToolItem API")] public Gtk.Widget InsertItem (string text, string tooltip_text, string tooltip_private_text, Gtk.Widget icon, Gtk.SignalFunc cb, IntPtr user_data, int position) { - GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); + GtkSharp.SignalFuncWrapper cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr ntext = GLib.Marshaller.StringToPtrGStrdup (text); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); @@ -172,8 +167,7 @@ [Obsolete ("Replaced by ToolItem API")] public Gtk.Widget PrependItem (string text, string tooltip_text, string tooltip_private_text, Gtk.Widget icon, Gtk.SignalFunc cb) { - GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); + GtkSharp.SignalFuncWrapper cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr ntext = GLib.Marshaller.StringToPtrGStrdup (text); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); @@ -203,8 +197,7 @@ [Obsolete ("Replaced by ToolItem API")] public Gtk.Widget InsertStock (string stock_id, string tooltip_text, string tooltip_private_text, Gtk.SignalFunc cb, IntPtr user_data, int position) { - GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); + GtkSharp.SignalFuncWrapper cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr nstock = GLib.Marshaller.StringToPtrGStrdup (stock_id); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); diff --git a/gtk/TreeModelFilter.custom b/gtk/TreeModelFilter.custom index 14c7a65f3..49075ba58 100644 --- a/gtk/TreeModelFilter.custom +++ b/gtk/TreeModelFilter.custom @@ -58,53 +58,35 @@ return ret; } - [GLib.CDeclCallback] - delegate void DestroyNotify (IntPtr data); - - static void ReleaseCallback (IntPtr data) - { - if (data == IntPtr.Zero) - return; - GCHandle gch = (GCHandle) data; - gch.Free (); - } - - static DestroyNotify release_callback; - - [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_tree_model_filter_set_visible_func (IntPtr raw, GtkSharp.TreeModelFilterVisibleFuncNative func, IntPtr data, GtkSharp.DestroyNotifyNative destroy); - [Obsolete ("Replaced by SetVisibleFunc (TreeModelFilterVisibleFunc) overload.")] public void SetVisibleFunc (TreeModelFilterVisibleFunc func, IntPtr data, Gtk.DestroyNotify destroy) { - GtkSharp.TreeModelFilterVisibleFuncWrapper func_wrapper = new GtkSharp.TreeModelFilterVisibleFuncWrapper (func); - GtkSharp.DestroyNotifyWrapper destroy_wrapper = new GtkSharp.DestroyNotifyWrapper (destroy); - gtk_tree_model_filter_set_visible_func (Handle, func_wrapper.NativeDelegate, data, destroy_wrapper.NativeDelegate); + SetVisibleFunc (func); } [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_tree_model_filter_set_visible_func (IntPtr raw, GtkSharp.TreeModelFilterVisibleFuncNative func, IntPtr data, DestroyNotify destroy); + static extern void gtk_tree_model_filter_set_visible_func (IntPtr raw, GtkSharp.TreeModelFilterVisibleFuncNative func, IntPtr data, NativeDestroyNotify destroy); public void SetVisibleFunc (TreeModelFilterVisibleFunc func) { + if (func == null) { + gtk_tree_model_filter_set_visible_func (Handle, null, IntPtr.Zero, null); + return; + } GtkSharp.TreeModelFilterVisibleFuncWrapper func_wrapper = new GtkSharp.TreeModelFilterVisibleFuncWrapper (func); - if (release_callback == null) - release_callback = new DestroyNotify (ReleaseCallback); GCHandle gch = GCHandle.Alloc (func_wrapper); - gtk_tree_model_filter_set_visible_func (Handle, func_wrapper.NativeDelegate, (IntPtr) gch, release_callback); + gtk_tree_model_filter_set_visible_func (Handle, func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); } [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_tree_model_filter_set_modify_func(IntPtr raw, int n_columns, IntPtr[] types, GtkSharp.TreeModelFilterModifyFuncNative func, IntPtr data, DestroyNotify destroy); + static extern void gtk_tree_model_filter_set_modify_func(IntPtr raw, int n_columns, IntPtr[] types, GtkSharp.TreeModelFilterModifyFuncNative func, IntPtr data, NativeDestroyNotify destroy); public void SetModifyFunc (int n_columns, GLib.GType[] types, TreeModelFilterModifyFunc func) { GtkSharp.TreeModelFilterModifyFuncWrapper func_wrapper = new GtkSharp.TreeModelFilterModifyFuncWrapper (func); - if (release_callback == null) - release_callback = new DestroyNotify (ReleaseCallback); IntPtr[] native_types = new IntPtr [types.Length]; for (int i = 0; i < types.Length; i++) native_types [i] = types [i].Val; GCHandle gch = GCHandle.Alloc (func_wrapper); - gtk_tree_model_filter_set_modify_func (Handle, n_columns, native_types, func_wrapper.NativeDelegate, (IntPtr) gch, release_callback); + gtk_tree_model_filter_set_modify_func (Handle, n_columns, native_types, func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); } diff --git a/gtk/TreeModelSort.custom b/gtk/TreeModelSort.custom index e7d8ef1aa..c2a788d8d 100644 --- a/gtk/TreeModelSort.custom +++ b/gtk/TreeModelSort.custom @@ -86,44 +86,44 @@ } [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); - } - - [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_tree_sortable_set_sort_func(IntPtr raw, int col_id, IntPtr sort_func, IntPtr user_data, IntPtr destroy); - - [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_tree_sortable_set_sort_func(IntPtr raw, int col_id, GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, GtkSharp.DestroyNotifyNative destroy); + static extern void gtk_tree_sortable_set_sort_func(IntPtr raw, int col_id, GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, NativeDestroyNotify destroy); + [Obsolete ("Replaced by SetSortFunc (int, TreeIterCompareFunc) overload.")] public void SetSortFunc (int sort_column_id, TreeIterCompareFunc sort_func, IntPtr user_data, Gtk.DestroyNotify destroy) + { + SetSortFunc (sort_column_id, sort_func); + } + + public void SetSortFunc (int sort_column_id, TreeIterCompareFunc sort_func) { if (sort_func == null) { - PersistentData ["column_" + sort_column_id + "_sort_func"] = null; - gtk_tree_sortable_set_sort_func (Handle, sort_column_id, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); + gtk_tree_sortable_set_sort_func (Handle, sort_column_id, null, IntPtr.Zero, null); return; } GtkSharp.TreeIterCompareFuncWrapper sort_func_wrapper = new GtkSharp.TreeIterCompareFuncWrapper (sort_func); - PersistentData ["column_" + sort_column_id + "_sort_func"] = sort_func_wrapper; - GtkSharp.DestroyNotifyWrapper destroy_wrapper = null; - destroy_wrapper = new GtkSharp.DestroyNotifyWrapper (destroy); - gtk_tree_sortable_set_sort_func(Handle, sort_column_id, sort_func_wrapper.NativeDelegate, user_data, destroy_wrapper.NativeDelegate); + GCHandle gch = GCHandle.Alloc (sort_func_wrapper); + gtk_tree_sortable_set_sort_func(Handle, sort_column_id, sort_func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); + } + + [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, NativeDestroyNotify destroy); + + [Obsolete ("Replaced by SetDefaultSortFunc (TreeIterCompareFunc) overload.")] + public void SetDefaultSortFunc (TreeIterCompareFunc sort_func, IntPtr user_data, Gtk.DestroyNotify destroy) + { + SetDefaultSortFunc (sort_func); + } + + public void SetDefaultSortFunc (TreeIterCompareFunc sort_func) + { + if (sort_func == null) { + gtk_tree_sortable_set_default_sort_func (Handle, null, IntPtr.Zero, null); + return; + } + + GtkSharp.TreeIterCompareFuncWrapper sort_func_wrapper = new GtkSharp.TreeIterCompareFuncWrapper (sort_func); + GCHandle gch = GCHandle.Alloc (sort_func_wrapper); + gtk_tree_sortable_set_default_sort_func(Handle, sort_func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); } diff --git a/gtk/TreeSortable.custom b/gtk/TreeSortable.custom index 4cc6c4d78..95252dd46 100644 --- a/gtk/TreeSortable.custom +++ b/gtk/TreeSortable.custom @@ -20,7 +20,13 @@ // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. + [Obsolete ("Replaced by SetDefaultSortFunc (TreeIterCompareFunc) overload.")] void SetDefaultSortFunc (TreeIterCompareFunc sort_func, IntPtr user_data, Gtk.DestroyNotify destroy); + void SetDefaultSortFunc (TreeIterCompareFunc sort_func); + + [Obsolete ("Replaced by SetSortFunc (int, TreeIterCompareFunc) overload.")] void SetSortFunc (int sort_column_id, TreeIterCompareFunc sort_func, IntPtr user_data, Gtk.DestroyNotify destroy); + void SetSortFunc (int sort_column_id, TreeIterCompareFunc sort_func); + diff --git a/gtk/TreeStore.custom b/gtk/TreeStore.custom index a398a6fde..9bb67517f 100644 --- a/gtk/TreeStore.custom +++ b/gtk/TreeStore.custom @@ -326,44 +326,44 @@ } [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); - } - - [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_tree_sortable_set_sort_func(IntPtr raw, int col_id, IntPtr sort_func, IntPtr user_data, IntPtr destroy); - - [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_tree_sortable_set_sort_func(IntPtr raw, int col_id, GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, GtkSharp.DestroyNotifyNative destroy); + static extern void gtk_tree_sortable_set_sort_func(IntPtr raw, int col_id, GtkSharp.TreeIterCompareFuncNative sort_func, IntPtr user_data, NativeDestroyNotify destroy); + [Obsolete ("Replaced by SetSortFunc (int, TreeIterCompareFunc) overload.")] public void SetSortFunc (int sort_column_id, TreeIterCompareFunc sort_func, IntPtr user_data, Gtk.DestroyNotify destroy) + { + SetSortFunc (sort_column_id, sort_func); + } + + public void SetSortFunc (int sort_column_id, TreeIterCompareFunc sort_func) { if (sort_func == null) { - PersistentData ["column_" + sort_column_id + "_sort_func"] = null; - gtk_tree_sortable_set_sort_func (Handle, sort_column_id, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); + gtk_tree_sortable_set_sort_func (Handle, sort_column_id, null, IntPtr.Zero, null); return; } GtkSharp.TreeIterCompareFuncWrapper sort_func_wrapper = new GtkSharp.TreeIterCompareFuncWrapper (sort_func); - PersistentData ["column_" + sort_column_id + "_sort_func"] = sort_func_wrapper; - GtkSharp.DestroyNotifyWrapper destroy_wrapper = null; - destroy_wrapper = new GtkSharp.DestroyNotifyWrapper (destroy); - gtk_tree_sortable_set_sort_func(Handle, sort_column_id, sort_func_wrapper.NativeDelegate, user_data, destroy_wrapper.NativeDelegate); + GCHandle gch = GCHandle.Alloc (sort_func_wrapper); + gtk_tree_sortable_set_sort_func(Handle, sort_column_id, sort_func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); + } + + [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, NativeDestroyNotify destroy); + + [Obsolete ("Replaced by SetDefaultSortFunc (TreeIterCompareFunc) overload.")] + public void SetDefaultSortFunc (TreeIterCompareFunc sort_func, IntPtr user_data, Gtk.DestroyNotify destroy) + { + SetDefaultSortFunc (sort_func); + } + + public void SetDefaultSortFunc (TreeIterCompareFunc sort_func) + { + if (sort_func == null) { + gtk_tree_sortable_set_default_sort_func (Handle, null, IntPtr.Zero, null); + return; + } + + GtkSharp.TreeIterCompareFuncWrapper sort_func_wrapper = new GtkSharp.TreeIterCompareFuncWrapper (sort_func); + GCHandle gch = GCHandle.Alloc (sort_func_wrapper); + gtk_tree_sortable_set_default_sort_func(Handle, sort_func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); } diff --git a/gtk/TreeViewColumn.custom b/gtk/TreeViewColumn.custom index ede595e01..be8098baa 100644 --- a/gtk/TreeViewColumn.custom +++ b/gtk/TreeViewColumn.custom @@ -66,61 +66,51 @@ } } - Hashtable CellDataFuncs { - get { - if (PersistentData ["gtksharp_cell_data_funcs"] == null) - PersistentData ["gtksharp_cell_data_funcs"] = new Hashtable (); - return PersistentData ["gtksharp_cell_data_funcs"] as Hashtable; - } - } + [DllImport("libgtk-win32-2.0-0.dll")] + static extern void gtk_tree_view_column_set_cell_data_func (IntPtr raw, IntPtr cell_renderer, GtkSharp.TreeCellDataFuncNative func, IntPtr func_data, NativeDestroyNotify destroy); [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_tree_view_column_set_cell_data_func(IntPtr raw, IntPtr cell_renderer, IntPtr func, IntPtr func_data, IntPtr destroy); - - private void ReleaseDataFunc (CellRenderer cell) - { - CellDataFuncs [cell.Handle] = null; - gtk_tree_view_column_set_cell_data_func(Handle, cell.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); - } - - [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_tree_view_column_set_cell_data_func(IntPtr raw, IntPtr cell_renderer, GtkSharp.TreeCellDataFuncNative func, IntPtr func_data, IntPtr destroy); - - [DllImport("libgtk-win32-2.0-0.dll")] - static extern void gtk_tree_view_column_set_cell_data_func(IntPtr raw, IntPtr cell_renderer, GtkSharp.CellLayoutDataFuncNative func, IntPtr func_data, IntPtr destroy); + static extern void gtk_tree_view_column_set_cell_data_func (IntPtr raw, IntPtr cell_renderer, GtkSharp.CellLayoutDataFuncNative func, IntPtr func_data, NativeDestroyNotify destroy); public void SetCellDataFunc (CellRenderer cell_renderer, TreeCellDataFunc func) { if (func == null) { - ReleaseDataFunc (cell_renderer); + gtk_tree_view_column_set_cell_data_func (Handle, cell_renderer == null ? IntPtr.Zero : cell_renderer.Handle, (GtkSharp.TreeCellDataFuncNative) null, IntPtr.Zero, null); return; } -; + GtkSharp.TreeCellDataFuncWrapper wrapper = new GtkSharp.TreeCellDataFuncWrapper (func); - CellDataFuncs [cell_renderer.Handle] = wrapper; - gtk_tree_view_column_set_cell_data_func(Handle, cell_renderer.Handle, wrapper.NativeDelegate, IntPtr.Zero, IntPtr.Zero); - } - public void SetCellDataFunc (CellRenderer cell_renderer, CellLayoutDataFunc func) - { - if (func == null) { - ReleaseDataFunc (cell_renderer); - return; - } -; - GtkSharp.CellLayoutDataFuncWrapper wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func); - CellDataFuncs [cell_renderer.Handle] = wrapper; - gtk_tree_view_column_set_cell_data_func(Handle, cell_renderer.Handle, wrapper.NativeDelegate, IntPtr.Zero, IntPtr.Zero); + GCHandle gch = GCHandle.Alloc (wrapper); + gtk_tree_view_column_set_cell_data_func (Handle, cell_renderer == null ? IntPtr.Zero : cell_renderer.Handle, wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); } - public void SetCellDataFunc (CellRenderer cell_renderer, NodeCellDataFunc func) + public void SetCellDataFunc (CellRenderer cell_renderer, CellLayoutDataFunc func) { if (func == null) { - ReleaseDataFunc (cell_renderer); + gtk_tree_view_column_set_cell_data_func (Handle, cell_renderer == null ? IntPtr.Zero : cell_renderer.Handle, (GtkSharp.TreeCellDataFuncNative) null, IntPtr.Zero, null); return; } -; - NodeCellDataFuncWrapper wrapper = new NodeCellDataFuncWrapper (func); - CellDataFuncs [cell_renderer.Handle] = wrapper; - gtk_tree_view_column_set_cell_data_func(Handle, cell_renderer.Handle, wrapper.NativeDelegate, IntPtr.Zero, IntPtr.Zero); + + GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func); + GCHandle gch = GCHandle.Alloc (func_wrapper); + gtk_tree_view_column_set_cell_data_func (Handle, cell_renderer == null ? IntPtr.Zero : cell_renderer.Handle, func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); + } + + public void SetCellDataFunc (CellRenderer cell_renderer, NodeCellDataFunc func) + { + if (func == null) { + gtk_tree_view_column_set_cell_data_func (Handle, cell_renderer == null ? IntPtr.Zero : cell_renderer.Handle, (GtkSharp.TreeCellDataFuncNative) null, IntPtr.Zero, null); + return; + } + + NodeCellDataFuncWrapper func_wrapper = new NodeCellDataFuncWrapper (func); + GCHandle gch = GCHandle.Alloc (func_wrapper); + gtk_tree_view_column_set_cell_data_func (Handle, cell_renderer == null ? IntPtr.Zero : cell_renderer.Handle, func_wrapper.NativeDelegate, (IntPtr) gch, DestroyHelper.NotifyHandler); + } + + [Obsolete ("Replaced by SetCellDataFunc (CellRenderer, TreeCellDataFunc) overload")] + public void SetCellDataFunc (Gtk.CellRenderer cell_renderer, Gtk.TreeCellDataFunc func, IntPtr func_data, Gtk.DestroyNotify destroy) + { + SetCellDataFunc (cell_renderer, func); }