Totally reworked the signal system. Should be much more flexable.

svn path=/trunk/gtk-sharp/; revision=919
This commit is contained in:
Bob Smith 2001-09-21 14:03:17 +00:00
parent 3d40a27630
commit 33533985d0
10 changed files with 261 additions and 123 deletions

View File

@ -1,3 +1,7 @@
2001-09-21
* Signal system totally reworked. It should be stable now.
2001-09-20
* glib/ObjectManager.cs: Nuked.

64
gdk/Event.cs Normal file
View File

@ -0,0 +1,64 @@
namespace Gdk {
using System;
using System.Runtime.InteropServices;
public enum EventType
{
Nothing = -1,
Delete = 0,
Destroy = 1,
Expose = 2,
MotionNotify = 3,
ButtonPress = 4,
2ButtonPress = 5,
3ButtonPress = 6,
ButtonRelease = 7,
KeyPress = 8,
KeyRelease = 9,
EnterNotify = 10,
LeaveNotify = 11,
FocusChange = 12,
Configure = 13,
Map = 14,
Unmap = 15,
PropertyNotify = 16,
SelectionClear = 17,
SelectionRequest = 18,
SelectionNotify = 19,
ProximityIn = 20,
ProximityOut = 21,
DragEnter = 22,
DragLeave = 23,
DragMotion = 24,
DragStatus = 25,
DropStart = 26,
DropFinished = 27,
ClientEvent = 28,
VisibilityNotify = 29,
NoExpose = 30,
Scroll = 31,
WindowState = 32,
Setting = 33
}
public class Event
{
public Event(IntPtr e)
{
_event = e;
}
protected IntPtr _event;
public EventType Type
{
get
{
IntPtr ptr = Marshal.ReadIntPtr (_event);
return (EventType)((int)ptr);
}
set
{
Marshal.WriteIntPtr(_event, new IntPtr((int)value));
}
}
}
}

View File

@ -0,0 +1,61 @@
// Gdk.Signals.SimpleEvent.cs - Gdk Simple Event Signal implementation
//
// Author: Bob Smith <bob@thestuff.net>
//
// (c) 2001 Bob Smith
namespace Gdk.Signals {
using System;
using System.Runtime.InteropServices;
using Glib;
using Gdk;
public class SimpleEventArgs : EventArgs {
public SimpleEventArgs(Gdk.Event event)
{
_event = event;
}
private Gdk.Event _event;
public Gdk.Event Event
{
get
{
return _event;
}
}
public static explicit operator Gdk.Event(SimpleEventArgs value)
{
return value.Event;
}
}
public delegate bool SimpleEventDelegate(IntPtr obj, IntPtr data);
public class SimpleEvent {
public SimpleEvent(){}
private static bool SimpleEventCallback(IntPtr obj, IntPtr e, IntPtr data)
{
Glib.Object o = Glib.Object.GetObject(obj);
EventHandler eh = o.Events[(int)data];
if (eh != null)
{
EventArgs args = new SimpleEventArgs (new Gdk.Event(e));
eh(o, args);
}
return true; //FIXME: How do we manage the return value?
}
private static SimpleEventDelegate _simpleDelegate;
private static GCHandle _simpleEventGCHandle;
public static SimpleEventDelegate Delegate
{
get
{
if (SimpleEvent._simpleEventDelegate == null)
{
SimpleEvent._simpleDelegate = new SimpleEventDelegate(SimpleCallback);
SimpleEvent._simpleGCHandle = GCHandle.Alloc (SimpleEvent._simpleEventDelegate, GCHandleType.Pinned);
}
return SimpleEvent._simpleEventDelegate;
}
}
}
}

11
gdk/makefile Executable file
View File

@ -0,0 +1,11 @@
CSC=/cygdrive/c/windows/microsoft.net/framework/v1.0.2914/csc.exe
all:
@echo "You must use 'make windows' or 'make unix'."
@echo "'make unix' is broken for now."
windows:
$(CSC) /unsafe /target:library /out:gdk-sharp.dll /recurse:*.cs
unix:
@echo "'make unix' is broken for now."

39
glib/Signals/Simple.cs Normal file
View File

@ -0,0 +1,39 @@
// Glib.Signals.Simple.cs - Glib Simple Signal implementation
//
// Author: Bob Smith <bob@thestuff.net>
//
// (c) 2001 Bob Smith
namespace Glib.Signals {
using System;
using System.Runtime.InteropServices;
using Glib;
public delegate void SimpleDelegate(IntPtr obj, IntPtr data);
public class Simple {
public Simple(){}
private static void SimpleCallback(IntPtr obj, IntPtr data)
{
Glib.Object o = Glib.Object.GetObject(obj);
EventHandler eh = o.Events[(int)data];
if (eh != null)
{
eh(o, EventArgs.Empty);
}
}
private static SimpleDelegate _simpleDelegate;
private static GCHandle _simpleGCHandle;
public static SimpleDelegate Delegate
{
get
{
if (Simple._simpleDelegate == null)
{
Simple._simpleDelegate = new SimpleDelegate(SimpleCallback);
Simple._simpleGCHandle = GCHandle.Alloc (Simple._simpleDelegate, GCHandleType.Pinned);
}
return Simple._simpleDelegate;
}
}
}
}

View File

@ -11,30 +11,16 @@ namespace Gtk {
public class Button : Widget {
private static readonly object ClickedEvent = new object ();
private static readonly string ClickedEvent = "clicked";
public event EventHandler Clicked
{
add
{
if (Events[ClickedEvent] == null)
{
ConnectSignal ("clicked", new SimpleCallback (EmitClickedEvent));
}
Events.AddHandler (ClickedEvent, value);
AddSimpleEvent(ClickedEvent, value);
}
remove
{
Events.RemoveHandler (ClickedEvent, value);
}
}
private void EmitClickedEvent (IntPtr obj)
{
EventHandler eh = (EventHandler)(Events[ClickedEvent]);
if (eh != null)
{
EventArgs args = new EventArgs ();
eh(this, args);
RemoveSimpleEvent (ClickedEvent, value);
}
}

View File

@ -12,60 +12,5 @@ namespace Gtk {
public abstract class Object : GLib.Object {
/// <summary>
/// Destroy Event
/// </summary>
///
/// <remarks>
/// Occurs when the Object is destroyed.
/// </remarks>
private static readonly object DestroyEvent = new object ();
public event EventHandler Destroy
{
add
{
if (Events[DestroyEvent] == null)
{
ConnectSignal ("destroy", new SimpleSignal (EmitDestroyEvent));
}
Events.AddHandler (DeleteEvent, value);
}
remove
{
Events.RemoveHandler (DeleteEvent, value);
}
}
private static void EmitDestroyEvent (IntPtr obj, IntPtr data)
{
Glib.Object o = Glib.Object.GetObject(obj);
EventHandler eh = (EventHandler)(o.Events[DeleteEvent]);
if (eh != null)
{
EventArgs args = new EventArgs ();
eh(this, args);
}
}
protected delegate void SimpleCallback (IntPtr obj);
[DllImport("gtk-1.3")]
static extern void gtk_signal_connect_full (
IntPtr obj, string evname,
SimpleCallback cb, IntPtr unsupported,
IntPtr data, IntPtr destroycb,
int objsig, int after );
protected void ConnectSignal (string name, SimpleCallback cb)
{
gtk_signal_connect_full (RawObject, name, cb,
new IntPtr (0), new IntPtr (0),
new IntPtr (0), 0, 0);
}
}
}

View File

@ -1,11 +0,0 @@
// SimpleSignal.cs - Simple callback delegate.
//
// Author: Bob Smith <bob@thestuff.net>
//
// (c) 2001 Bob Smith
namespace Gtk {
using System;
public delegate void SimpleSignal (IntPtr obj, IntPtr data);
}

View File

@ -6,63 +6,102 @@
namespace Gtk {
using System;
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;
using Glib;
using Gdk;
public abstract class Widget : Object {
public abstract class Widget : Object {
/// <summary>
/// Delete Event
/// </summary>
///
/// <remarks>
/// Occurs when the Widget is deleted by the window
/// manager.
/// </remarks>
private static readonly object DeleteEvent = new object ();
public event EventHandler Delete
private static readonly string DeleteEvent = "delete-event";
public event EventHandler DeleteEvent
{
add
{
if (Events[DeleteEvent] == null)
{
ConnectSignal ("delete-event", new SimpleCallback (EmitDeleteEvent));
}
Events.AddHandler (DeleteEvent, value);
AddGdkSimpleEvent(DeleteEvent, value);
}
remove
{
Events.RemoveHandler (DeleteEvent, value);
RemoveGdkSimpleEvent (DeleteEvent, value);
}
}
private void EmitDeleteEvent (IntPtr obj)
public void AddSimpleEvent(Object type, string name, EventHandler value)
{
EventHandler eh = (EventHandler)(Events[DeleteEvent]);
if (eh != null)
if (Events[type] == null)
{
EventArgs args = new EventArgs ();
eh(this, args);
ConnectSimpleSignal(name, type);
}
Events.AddHandler(type, value);
}
/// <summary>
/// Show Method
/// </summary>
///
/// <remarks>
/// Makes the Widget visible on the display.
/// </remarks>
public void AddSimpleEvent(String type, EventHandle value)
: this (type, type, value) {}
public void RemoveSimpleEvent(Object type, string name, EventHander value)
{
Events.RemoveHandler(type, value);
}
public void RemoveSimpleEvent(String type, EventHandle value)
: this (type, type, value) {}
public void AddGdkSimpleEvent(Object type, string name, EventHandler value)
{
if (Events[type] == null)
{
ConnectGdkSimpleEventSignal(name, type);
}
Events.AddHandler(type, value);
}
public void AddGdkSimpleEvent(String type, EventHandle value)
: this (type, type, value) {}
public void RemoveGdkSimpleEvent(Object type, string name, EventHander value)
{
Events.RemoveHandler(type, value);
}
public void RemoveGdkSimpleEvent(String type, EventHandle value)
: this (type, type, value) {}
[DllImport("gtk-1.3")]
static extern void gtk_widget_show (IntPtr obj);
static extern void gtk_signal_connect_full (
IntPtr obj, string evname,
SimpleDelegate cb, IntPtr unsupported,
IntPtr data, IntPtr destroycb,
int objsig, int after );
public void Show ()
public void ConnectSimpleSignal(string name, Object signal)
{
gtk_widget_show (RawObject);
gtk_signal_connect_full(RawObject, name, Glib.Signals.Simple.Delegate,
new IntPtr (0), new IntPtr (signal.GetHashCode()),
new IntPtr (0), 0, 0);
}
}
public void ConnectGdkSimpleSignal(string name, Object signal)
{
gtk_signal_connect_full(RawObject, name, Gdk.Signals.SimpleEvent.Delegate,
new IntPtr (0), new IntPtr (signal.GetHashCode()),
new IntPtr (0), 0, 0);
}
/// <summary>
/// Show Method
/// </summary>
///
/// <remarks>
/// Makes the Widget visible on the display.
/// </remarks>
[DllImport("gtk-1.3")]
static extern void gtk_widget_show (IntPtr obj);
public void Show ()
{
gtk_widget_show (RawObject);
}
}
}

View File

@ -15,13 +15,13 @@ namespace GtkSamples {
{
Application.Init (ref args);
Window win = new Window ("Gtk# Hello World");
win.Delete += new EventHandler (delete_cb);
win.DeleteEvent += new EventHandler (Window_Delete);
win.Show ();
Application.Run ();
return 0;
}
static void delete_cb (object obj, EventArgs args)
static void Window_Delete (object obj, EventArgs args)
{
Application.Quit ();
}