From 3c0213de8805133334deb556384a999caf837541 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 4 Oct 2001 20:59:48 +0000 Subject: [PATCH] 2001-10-04 Mike Kestner * gdk/SimpleEvent.cs : Temporarily comment the GCHandle code until a layout is ready and exceptions can be avoided. * gtk/Widget.cs : Killed all the signal and event attaching methods. They never belonged here, and now they exist in the SimpleEvent. Add a Signals hash to hold refs of the Signal handlers. Killed default ctor and the dtor. The event Add/Remove methods now create a SimpleEvent, stuff it in the hash, and remove it when the last handler disappears. svn path=/trunk/gtk-sharp/; revision=1078 --- ChangeLog | 11 ++++++ gdk/SimpleEvent.cs | 9 +++-- gtk/Widget.cs | 87 ++++------------------------------------------ 3 files changed, 25 insertions(+), 82 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0857a4ecc..9c27fb7b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2001-10-04 Mike Kestner + + * gdk/SimpleEvent.cs : Temporarily uncomment the GCHandle code until + a layout is ready and exceptions can be avoided. + * gtk/Widget.cs : Killed all the signal and event attaching methods. + They never belonged here, and now they exist in the SimpleEvent. + Add a Signals hash to hold refs of the Signal handlers. Killed default + ctor and the dtor. The event Add/Remove methods now create a + SimpleEvent, stuff it in the hash, and remove it when the last handler + disappears. + 2001-10-04 Mike Kestner * HACKING : Little bit of cleanup. diff --git a/gdk/SimpleEvent.cs b/gdk/SimpleEvent.cs index e88e29505..349a95626 100644 --- a/gdk/SimpleEvent.cs +++ b/gdk/SimpleEvent.cs @@ -1,8 +1,9 @@ -// Gdk.Signals.SimpleEvent.cs - Gdk Simple Event Signal implementation +// Gdk.SimpleEvent.cs - Gdk Simple Event Signal implementation // // Author: Bob Smith +// Mike Kestner // -// (c) 2001 Bob Smith +// (c) 2001 Bob Smith and Mike Kestner namespace Gdk { using System; @@ -104,8 +105,10 @@ namespace Gdk { if (_Delegate == null) { _Delegate = new SimpleEventDelegate ( SimpleEventCallback); + /* FIXME: Exception thrown for lack of layout _GCHandle = GCHandle.Alloc ( _Delegate, GCHandleType.Pinned); + */ } _key = _NextKey++; @@ -127,7 +130,9 @@ namespace Gdk { _Instances.Remove (_key); if (_Instances.Count == 0) { + /* FIXME: when the handle can be obtained _GCHandle.Free(); + */ _Delegate = null; } } diff --git a/gtk/Widget.cs b/gtk/Widget.cs index 9c3dcd986..c34286f1a 100755 --- a/gtk/Widget.cs +++ b/gtk/Widget.cs @@ -7,107 +7,34 @@ namespace Gtk { using System; + using System.Collections; using System.Runtime.InteropServices; using GLib; using Gdk; public class Widget : Object { - public Widget() {} - ~Widget() - { - /* FIXME: Find a valid way to Delete the handlers - foreach (EventHandler e in Events[DelEvName]) - { - DeleteEvent -= e; - } - */ - } private static readonly string DelEvName = "delete-event"; + private Hashtable Signals = new Hashtable (); + public event EventHandler DeleteEvent { add { if (Events [DelEvName] == null) - ConnectSignal(DelEvName); + Signals [DelEvName] = new SimpleEvent ( + this, RawObject, + DelEvName, value); Events.AddHandler(DelEvName, value); } remove { Events.RemoveHandler(DelEvName, value); if (Events [DelEvName] == null) - DisconnectSignal (DelEvName); - } - } -/* - public void AddSimpleEvent(Object type, string name, EventHandler value) - { - if (Events[type] == null) - { - ConnectSimpleSignal(name, type); - } - Events.AddHandler(type, value); - } - - public void RemoveSimpleEvent(Object type, string name, EventHandler value) - { - Events.RemoveHandler(type, value); - if (Events[type] == null) - { - DisconnectSimpleSignal(name, type); + Signals.Remove (DelEvName); } } - public void AddGdkSimpleEvent(Object type, string name, EventHandler value) - { - if (Events[type] == null) - { - ConnectGdkSimpleEventSignal(name, type); - } - Events.AddHandler(type, value); - } - - public void RemoveGdkSimpleEvent(Object type, string name, EventHandler value) - { - Events.RemoveHandler(type, value); - if (Events[type] == null) - { - DisconnectGdkSimpleEventSignal(name, type); - } - } -*/ - [DllImport("gtk-1.3.dll")] - static extern void gtk_signal_connect_full ( - IntPtr obj, string evname, - SimpleDelegate cb, IntPtr unsupported, - String data, IntPtr destroycb, - int objsig, int after ); - - public void ConnectSignal(string name) - { - gtk_signal_connect_full(RawObject, name, SimpleSignal.Delegate, - new IntPtr (0), name, - new IntPtr (0), 0, 0); - } - - public void DisconnectSignal(string name) - { - SimpleSignal.Unref(); - } - -/* - public void ConnectGdkSimpleSignal(string name, Object signal) - { - gtk_signal_connect_full(RawObject, name, SimpleEvent.Delegate, - new IntPtr (0), name, - new IntPtr (0), 0, 0); - } - - public void DisconnectGdkSimpleSignal(string name, Object signal) - { - SimpleEvent.Unref(); - } -*/ /// /// Show Method ///