Added refcounts to delegates to make sure they can be unpined when not needed.
svn path=/trunk/gtk-sharp/; revision=962
This commit is contained in:
parent
5056f3e4b3
commit
699238daad
6 changed files with 82 additions and 2 deletions
|
@ -1,3 +1,7 @@
|
|||
2001-09-25
|
||||
* Added refcounts to delegates to make sure they can be unpined when
|
||||
not needed.
|
||||
|
||||
2001-09-21
|
||||
|
||||
* Signal system totally reworked. It should be stable now.
|
||||
|
|
19
gdk/Event.cs
19
gdk/Event.cs
|
@ -60,5 +60,24 @@ namespace Gdk {
|
|||
Marshal.WriteIntPtr(_event, new IntPtr((int)value));
|
||||
}
|
||||
}
|
||||
public EventAny Any
|
||||
{
|
||||
get
|
||||
{
|
||||
return (EventAll)this;
|
||||
}
|
||||
}
|
||||
public static explicit EventAll (Event e)
|
||||
{
|
||||
return Marshal.PtrToStructure(e._event, EventAll);
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct EventAny
|
||||
{
|
||||
public IntPtr type;
|
||||
public IntPtr window;
|
||||
public SByte send_event;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ namespace Gdk.Signals {
|
|||
}
|
||||
return true; //FIXME: How do we manage the return value?
|
||||
}
|
||||
private static int _simpleRefCount;
|
||||
private static SimpleEventDelegate _simpleDelegate;
|
||||
private static GCHandle _simpleEventGCHandle;
|
||||
public static SimpleEventDelegate Delegate
|
||||
|
@ -54,8 +55,19 @@ namespace Gdk.Signals {
|
|||
SimpleEvent._simpleDelegate = new SimpleEventDelegate(SimpleCallback);
|
||||
SimpleEvent._simpleGCHandle = GCHandle.Alloc (SimpleEvent._simpleEventDelegate, GCHandleType.Pinned);
|
||||
}
|
||||
SimpleEvent._simpleRefCount++;
|
||||
return SimpleEvent._simpleEventDelegate;
|
||||
}
|
||||
}
|
||||
public static void Unref()
|
||||
{
|
||||
SimpleEvent._simpleRefCount--;
|
||||
if (SimpleEvent._simpleRefCount < 1)
|
||||
{
|
||||
SimpleEvent._simpleRefCount = 0;
|
||||
SimpleEvent._simpleEventGCHandle.free();
|
||||
SimpleEvent._simpleDelegate = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace Glib.Signals {
|
|||
eh(o, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
private static int _simpleRefCount = 0;
|
||||
private static SimpleDelegate _simpleDelegate;
|
||||
private static GCHandle _simpleGCHandle;
|
||||
public static SimpleDelegate Delegate
|
||||
|
@ -32,8 +33,19 @@ namespace Glib.Signals {
|
|||
Simple._simpleDelegate = new SimpleDelegate(SimpleCallback);
|
||||
Simple._simpleGCHandle = GCHandle.Alloc (Simple._simpleDelegate, GCHandleType.Pinned);
|
||||
}
|
||||
Simple._simpleRefCount++;
|
||||
return Simple._simpleDelegate;
|
||||
}
|
||||
}
|
||||
public static void Unref()
|
||||
{
|
||||
Simple._simpleRefCount--;
|
||||
if (Simple._simpleRefCount < 1)
|
||||
{
|
||||
Simple._simpleRefCount = 0;
|
||||
Simple._simpleGCHandle.free();
|
||||
Simple._simpleDelegate = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,14 @@ namespace Gtk {
|
|||
RawObject = o;
|
||||
}
|
||||
|
||||
public ~Button ()
|
||||
{
|
||||
foreach (EventHandler e in Events[ClickedEvent])
|
||||
{
|
||||
Clicked -= e;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Button Constructor
|
||||
/// </summary>
|
||||
|
|
|
@ -11,8 +11,15 @@ namespace Gtk {
|
|||
using Glib;
|
||||
using Gdk;
|
||||
|
||||
public abstract class Widget : Object {
|
||||
|
||||
public class Widget : Object {
|
||||
public Widget() {}
|
||||
public ~Widget()
|
||||
{
|
||||
foreach (EventHandler e in Events[DeleteEvent])
|
||||
{
|
||||
DeleteEvent -= e;
|
||||
}
|
||||
}
|
||||
private static readonly string DeleteEvent = "delete-event";
|
||||
public event EventHandler DeleteEvent
|
||||
{
|
||||
|
@ -41,6 +48,10 @@ namespace Gtk {
|
|||
public void RemoveSimpleEvent(Object type, string name, EventHander value)
|
||||
{
|
||||
Events.RemoveHandler(type, value);
|
||||
if (Events[type] == null)
|
||||
{
|
||||
DisconnectSimpleSignal(name, type);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveSimpleEvent(String type, EventHandle value)
|
||||
|
@ -61,6 +72,10 @@ namespace Gtk {
|
|||
public void RemoveGdkSimpleEvent(Object type, string name, EventHander value)
|
||||
{
|
||||
Events.RemoveHandler(type, value);
|
||||
if (Events[type] == null)
|
||||
{
|
||||
DisconnectGdkSimpleEventSignal(name, type);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveGdkSimpleEvent(String type, EventHandle value)
|
||||
|
@ -81,6 +96,11 @@ namespace Gtk {
|
|||
new IntPtr (0), 0, 0);
|
||||
}
|
||||
|
||||
public void DisconnectSimpleSignal(string name, Object signal)
|
||||
{
|
||||
Glib.Signals.Simple.Unref();
|
||||
}
|
||||
|
||||
public void ConnectGdkSimpleSignal(string name, Object signal)
|
||||
{
|
||||
gtk_signal_connect_full(RawObject, name, Gdk.Signals.SimpleEvent.Delegate,
|
||||
|
@ -88,6 +108,11 @@ namespace Gtk {
|
|||
new IntPtr (0), 0, 0);
|
||||
}
|
||||
|
||||
public void DisconnectGdkSimpleSignal(string name, Object signal)
|
||||
{
|
||||
Gdk.Signals.SimpleEvent.Unref();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show Method
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in a new issue