2003-02-26 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* generator/Parser.cs: use XmlDocument.Load (Stream). The one using
	(String) expects an uri.

	* generator/Signal.cs: always remove the delegate from the signal
	callback (prior to this, the last handler was not being removed).
	Dispose the callback (ie, disconnect from the signal) when there are
	no registered delegates to handle it.

	* generator/SignalHandler.cs: added 2 new fields to hold the instance
	and the handler ID. The finalization is now done in Dispose and
	disconnects the signal handler when no delegate will handle the signal.
	Changed gobject-2.0 to libgobject-2.0-0.dll.

	* glib/SignalCallback.cs: implemented IDisposable interface.

svn path=/trunk/gtk-sharp/; revision=11976
This commit is contained in:
Gonzalo Paniagua Javier 2003-02-26 02:16:38 +00:00
parent f674efc1e8
commit 4a6b18ee0f
5 changed files with 64 additions and 9 deletions

View file

@ -1,3 +1,20 @@
2003-02-26 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* generator/Parser.cs: use XmlDocument.Load (Stream). The one using
(String) expects an uri.
* generator/Signal.cs: always remove the delegate from the signal
callback (prior to this, the last handler was not being removed).
Dispose the callback (ie, disconnect from the signal) when there are
no registered delegates to handle it.
* generator/SignalHandler.cs: added 2 new fields to hold the instance
and the handler ID. The finalization is now done in Dispose and
disconnects the signal handler when no delegate will handle the signal.
Changed gobject-2.0 to libgobject-2.0-0.dll.
* glib/SignalCallback.cs: implemented IDisposable interface.
2003-02-24 Mike Kestner <mkestner@speakeasy.net>
* sample/TreeViewDemo.cs : fix Type ambiguities

View file

@ -8,6 +8,7 @@ namespace GtkSharp.Generation {
using System;
using System.Collections;
using System.IO;
using System.Xml;
public class Parser {
@ -20,7 +21,9 @@ namespace GtkSharp.Generation {
try {
doc.Load (filename);
Stream stream = File.OpenRead (filename);
doc.Load (stream);
stream.Close ();
} catch (XmlException e) {

View file

@ -169,10 +169,16 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\t\t}");
sw.WriteLine("\t\t\tremove {");
sw.WriteLine("\t\t\t\tEventList.RemoveHandler(" + cname + ", value);");
sw.WriteLine("\t\t\t\tif (EventList[" + cname + "] == null)");
sw.WriteLine("\t\t\t\tGtkSharp.SignalCallback cb = Signals [{0}] as GtkSharp.SignalCallback;", cname);
sw.WriteLine("\t\t\t\tif (cb == null)");
sw.WriteLine("\t\t\t\t\treturn;");
sw.WriteLine();
sw.WriteLine("\t\t\t\tcb.RemoveDelegate (value);");
sw.WriteLine();
sw.WriteLine("\t\t\t\tif (EventList[" + cname + "] == null) {");
sw.WriteLine("\t\t\t\t\tSignals.Remove(" + cname + ");");
sw.WriteLine("\t\t\t\telse");
sw.WriteLine("\t\t\t\t\t((GtkSharp.SignalCallback) Signals [{0}]).RemoveDelegate (value);", cname);
sw.WriteLine("\t\t\t\t\tcb.Dispose ();");
sw.WriteLine("\t\t\t\t}");
sw.WriteLine("\t\t\t}");
sw.WriteLine("\t\t}");
sw.WriteLine();

View file

@ -109,6 +109,9 @@ namespace GtkSharp.Generation {
sw.WriteLine();
sw.WriteLine("\t\tprivate static " + dname + " _Delegate;");
sw.WriteLine();
sw.WriteLine("\t\tprivate IntPtr _raw;");
sw.WriteLine("\t\tprivate uint _HandlerID;");
sw.WriteLine();
sw.Write("\t\tprivate static " + p_ret + " ");
sw.WriteLine(cbname + "(" + pinv + ", int key)");
sw.WriteLine("\t\t{");
@ -162,8 +165,8 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\t}");
sw.WriteLine();
}
sw.Write("\t\t[DllImport(\"gobject-2.0\")]");
sw.Write("\t\tstatic extern void g_signal_connect_data(");
sw.WriteLine("\t\t[DllImport(\"libgobject-2.0-0.dll\")]");
sw.Write("\t\tstatic extern uint g_signal_connect_data(");
sw.Write("IntPtr obj, String name, " + dname + " cb, int key, IntPtr p,");
sw.WriteLine(" int flags);");
sw.WriteLine();
@ -173,14 +176,19 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\t\tif (_Delegate == null) {");
sw.WriteLine("\t\t\t\t_Delegate = new " + dname + "(" + cbname + ");");
sw.WriteLine("\t\t\t}");
sw.Write("\t\t\tg_signal_connect_data(raw, name, ");
sw.WriteLine("\t\t\t_raw = raw;");
sw.Write("\t\t\t_HandlerID = g_signal_connect_data(raw, name, ");
sw.WriteLine("_Delegate, _key, new IntPtr(0), 0);");
sw.WriteLine("\t\t}");
sw.WriteLine();
sw.WriteLine("\t\t~" + sname + "()");
sw.WriteLine("\t\t[DllImport(\"libgobject-2.0-0.dll\")]");
sw.WriteLine("\t\tstatic extern void g_signal_handler_disconnect (IntPtr instance, uint handler);");
sw.WriteLine();
sw.WriteLine("\t\tprotected override void Dispose (bool disposing)");
sw.WriteLine("\t\t{");
sw.WriteLine("\t\t\t_Instances.Remove(_key);");
sw.WriteLine("\t\t\tif(_Instances.Count == 0) {");
sw.WriteLine("\t\t\t\tg_signal_handler_disconnect (_raw, _HandlerID);");
sw.WriteLine("\t\t\t\t_Delegate = null;");
sw.WriteLine("\t\t\t}");
sw.WriteLine("\t\t}");

View file

@ -18,7 +18,7 @@ namespace GtkSharp {
/// Base Class for GSignal to C# event marshalling.
/// </remarks>
public abstract class SignalCallback {
public abstract class SignalCallback : IDisposable {
// A counter used to produce unique keys for instances.
protected static int _NextKey = 0;
@ -58,5 +58,26 @@ namespace GtkSharp {
{
_handler = Delegate.Remove (_handler, d);
}
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
if (disposing) {
_obj = null;
_handler = null;
_argstype = null;
}
}
~SignalCallback ()
{
Dispose (false);
}
}
}