2004-05-05 Mike Kestner <mkestner@ximian.com>

* generator/Signal.cs : rmv Handle param to SignalCallback ctor calls.
	s/GtkSharp.Signal*/GLib.Signal*.
	* generator/SignalHandler.cs : rmv Handle param to ctors as it's
	redundant.  s/GtkSharp.Signal*/GLib.Signal*. Use new Connect/Disconnect
	instead of generating DllImports into libgobject directly.
	* glib/SignalArgs.cs : move the the GLib namespace.
	* glib/SignalCallback.cs : expose Connect and Disconnect methods to
	hide some pinvokes that were previously generated. Also move to the
	GLib namespace.
	gnome/*Handler.cs : update to new SignalHandler API.
	gnome/CanvasProxy.cs : ditto
	gnome/void*Signal.cs : ditto

svn path=/trunk/gtk-sharp/; revision=26778
This commit is contained in:
Mike Kestner 2004-05-05 18:24:04 +00:00
parent 6fd6ecbbdb
commit 01acd7f576
12 changed files with 69 additions and 168 deletions

View file

@ -1,8 +1,23 @@
2004-05-05 Mike Kestner <mkestner@ximian.com>
* generator/Signal.cs : rmv Handle param to SignalCallback ctor calls.
s/GtkSharp.Signal*/GLib.Signal*.
* generator/SignalHandler.cs : rmv Handle param to ctors as it's
redundant. s/GtkSharp.Signal*/GLib.Signal*. Use new Connect/Disconnect
instead of generating DllImports into libgobject directly.
* glib/SignalArgs.cs : move the the GLib namespace.
* glib/SignalCallback.cs : expose Connect and Disconnect methods to
hide some pinvokes that were previously generated. Also move to the
GLib namespace.
gnome/*Handler.cs : update to new SignalHandler API.
gnome/CanvasProxy.cs : ditto
gnome/void*Signal.cs : ditto
2004-05-04 Mike Kestner <mkestner@ximian.com>
* sample/gconf/Makefile.am : fix some whitespace. I love you, auto*.
2004-05-05 Mike Kestner <mkestner@ximian.com>
2004-05-04 Mike Kestner <mkestner@ximian.com>
* configure.in : fix gtkhtml versioning *again*.
* sample/gconf/Makefile.am : conditional build on ENABLE_GNOME.

View file

@ -155,7 +155,7 @@ namespace GtkSharp.Generation {
sw.WriteLine ();
sw.WriteLine ("\tpublic delegate void " + EventHandlerName + "(object o, " + EventArgsName + " args);");
sw.WriteLine ();
sw.WriteLine ("\tpublic class " + EventArgsName + " : GtkSharp.SignalArgs {");
sw.WriteLine ("\tpublic class " + EventArgsName + " : GLib.SignalArgs {");
if (parms != null) {
for (int i = 1; i < parms.Count; i++) {
sw.WriteLine ("\t\tpublic " + parms[i].CSType + " " + parms[i].StudlyName + "{");
@ -253,22 +253,22 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\t\t\tif (value.Method.GetCustomAttributes(typeof(GLib.ConnectBeforeAttribute), false).Length > 0) {");
sw.WriteLine("\t\t\t\t\tif (BeforeHandlers[" + cname + "] == null)");
sw.Write("\t\t\t\t\t\tBeforeSignals[" + cname + "] = new " + qual_marsh);
sw.Write("(this, Handle, " + cname + ", value, System.Type.GetType(\"" + EventArgsQualifiedName);
sw.Write("(this, " + cname + ", value, System.Type.GetType(\"" + EventArgsQualifiedName);
if (EventArgsQualifiedName != "System.EventArgs")
sw.Write("," + gen_info.AssemblyName);
sw.WriteLine("\"), 0);");
sw.WriteLine("\t\t\t\t\telse");
sw.WriteLine("\t\t\t\t\t\t((GtkSharp.SignalCallback) BeforeSignals [{0}]).AddDelegate (value);", cname);
sw.WriteLine("\t\t\t\t\t\t((GLib.SignalCallback) BeforeSignals [{0}]).AddDelegate (value);", cname);
sw.WriteLine("\t\t\t\t\tBeforeHandlers.AddHandler(" + cname + ", value);");
sw.WriteLine("\t\t\t\t} else {");
sw.WriteLine("\t\t\t\t\tif (AfterHandlers[" + cname + "] == null)");
sw.Write("\t\t\t\t\t\tAfterSignals[" + cname + "] = new " + qual_marsh);
sw.Write("(this, Handle, " + cname + ", value, System.Type.GetType(\"" + EventArgsQualifiedName);
sw.Write("(this, " + cname + ", value, System.Type.GetType(\"" + EventArgsQualifiedName);
if (EventArgsQualifiedName != "System.EventArgs")
sw.Write("," + gen_info.AssemblyName);
sw.WriteLine("\"), 1);");
sw.WriteLine("\t\t\t\t\telse");
sw.WriteLine("\t\t\t\t\t\t((GtkSharp.SignalCallback) AfterSignals [{0}]).AddDelegate (value);", cname);
sw.WriteLine("\t\t\t\t\t\t((GLib.SignalCallback) AfterSignals [{0}]).AddDelegate (value);", cname);
sw.WriteLine("\t\t\t\t\tAfterHandlers.AddHandler(" + cname + ", value);");
sw.WriteLine("\t\t\t\t}");
sw.WriteLine("\t\t\t}");
@ -279,7 +279,7 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\t\t\t\tevent_list = BeforeHandlers;");
sw.WriteLine("\t\t\t\t\tsignals = BeforeSignals;");
sw.WriteLine("\t\t\t\t}");
sw.WriteLine("\t\t\t\tGtkSharp.SignalCallback cb = signals [{0}] as GtkSharp.SignalCallback;", cname);
sw.WriteLine("\t\t\t\tGLib.SignalCallback cb = signals [{0}] as GLib.SignalCallback;", cname);
sw.WriteLine("\t\t\t\tevent_list.RemoveHandler(" + cname + ", value);");
sw.WriteLine("\t\t\t\tif (cb == null)");
sw.WriteLine("\t\t\t\t\treturn;");

View file

@ -114,18 +114,14 @@ namespace GtkSharp.Generation {
sw.WriteLine();
sw.WriteLine("\tusing System;");
sw.WriteLine("\tusing System.Runtime.InteropServices;");
sw.WriteLine("\tusing GtkSharp;");
sw.WriteLine();
sw.Write("\tinternal delegate " + p_ret + " ");
sw.WriteLine(DelegateName + "(" + ISig + ", int key);");
sw.WriteLine();
sw.WriteLine("\tinternal class " + Name + " : SignalCallback {");
sw.WriteLine("\tinternal class " + Name + " : GLib.SignalCallback {");
sw.WriteLine();
sw.WriteLine("\t\tprivate static " + DelegateName + " _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(CallbackName + "(" + ISig + ", int key)");
sw.WriteLine("\t\t{");
@ -139,7 +135,7 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\t}");
sw.WriteLine();
} else {
sw.WriteLine("\t\t\tSignalArgs args = (SignalArgs) Activator.CreateInstance (inst._argstype);");
sw.WriteLine("\t\t\tGLib.SignalArgs args = (GLib.SignalArgs) Activator.CreateInstance (inst._argstype);");
if (parms.Count > 1) {
sw.WriteLine("\t\t\targs.Args = new object[" + (parms.Count-1) + "];");
}
@ -179,36 +175,22 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\t}");
sw.WriteLine();
}
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, " + DelegateName + " cb, int key, IntPtr p,");
sw.WriteLine(" int flags);");
sw.WriteLine();
sw.Write("\t\tpublic " + Name + "(GLib.Object obj, IntPtr raw, ");
sw.Write("\t\tpublic " + Name + "(GLib.Object obj, ");
sw.WriteLine("string name, Delegate eh, Type argstype, int connect_flags) : base(obj, eh, argstype)");
sw.WriteLine("\t\t{");
sw.WriteLine("\t\t\tif (_Delegate == null) {");
sw.WriteLine("\t\t\t\t_Delegate = new " + DelegateName + "(" + CallbackName + ");");
sw.WriteLine("\t\t\t}");
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), connect_flags);");
sw.WriteLine("\t\t\tConnect (name, _Delegate, connect_flags);");
sw.WriteLine("\t\t}");
sw.WriteLine();
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\t[DllImport(\"libgobject-2.0-0.dll\")]");
sw.WriteLine("\t\tstatic extern bool g_signal_handler_is_connected (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\t_Delegate = null;");
sw.WriteLine();
sw.WriteLine("\t\t\tif (g_signal_handler_is_connected (_raw, _HandlerID))");
sw.WriteLine("\t\t\t\tg_signal_handler_disconnect (_raw, _HandlerID);");
sw.WriteLine("\t\t\tDisconnect ();");
sw.WriteLine("\t\t\tbase.Dispose (disposing);");
sw.WriteLine("\t\t}");
sw.WriteLine("\t}");

View file

@ -1,79 +1,36 @@
// GtkSharp.SignalArgs.cs - Signal argument class implementation
// GLib.SignalArgs.cs - Signal argument class implementation
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001 Mike Kestner
namespace GtkSharp {
namespace GLib {
using System;
using System.Collections;
/// <summary>
/// SignalArgs Class
/// </summary>
///
/// <remarks>
/// Arguments and return value for signals.
/// </remarks>
public class SignalArgs : EventArgs {
private object _ret;
private object[] _args;
/// <summary>
/// SignalArgs Constructor
/// </summary>
///
/// <remarks>
/// Creates a SignalArgs object with no return value and
/// no arguments.
/// </remarks>
public SignalArgs()
{
_ret = null;
_args = null;
}
/// <summary>
/// SignalArgs Constructor
/// </summary>
///
/// <remarks>
/// Creates a SignalArgs object with a return value and
/// no arguments.
/// </remarks>
public SignalArgs(object retval)
{
_ret = retval;
_args = null;
}
/// <summary>
/// SignalArgs Constructor
/// </summary>
///
/// <remarks>
/// Creates a SignalArgs object with a return value and
/// a list of arguments.
/// </remarks>
public SignalArgs(object retval, object[] args)
{
_ret = retval;
_args = args;
}
/// <summary>
/// Args Property
/// </summary>
///
/// <remarks>
/// A list of arguments.
/// </remarks>
public object[] Args {
get {
return _args;
@ -83,14 +40,6 @@ namespace GtkSharp {
}
}
/// <summary>
/// RetVal Property
/// </summary>
///
/// <remarks>
/// The return value.
/// </remarks>
public object RetVal {
get {
return _ret;

View file

@ -1,22 +1,14 @@
// GtkSharp.SignalCallback.cs - Signal callback base class implementation
// GLib.SignalCallback.cs - Signal callback base class implementation
//
// Authors: Mike Kestner <mkestner@speakeasy.net>
// Authors: Mike Kestner <mkestner@ximian.com>
//
// (c) 2001 Mike Kestner
// Copyright (c) 2001 Mike Kestner
// Copyright (c) 2004 Novell, Inc.
namespace GtkSharp {
namespace GLib {
using System;
using System.Collections;
using System.Runtime.InteropServices;
using GLib;
/// <summary>
/// SignalCallback Class
/// </summary>
///
/// <remarks>
/// Base Class for GSignal to C# event marshalling.
/// </remarks>
public abstract class SignalCallback : IDisposable {
@ -31,14 +23,7 @@ namespace GtkSharp {
protected Delegate _handler;
protected int _key;
protected System.Type _argstype;
/// <summary>
/// SignalCallback Constructor
/// </summary>
///
/// <remarks>
/// Initializes instance data.
/// </remarks>
protected uint _HandlerID;
protected SignalCallback (GLib.Object obj, Delegate eh, System.Type argstype)
{
@ -59,6 +44,26 @@ namespace GtkSharp {
_handler = Delegate.Remove (_handler, d);
}
[DllImport("libgobject-2.0-0.dll")]
static extern uint g_signal_connect_data(IntPtr obj, string name, Delegate cb, int key, IntPtr p, int flags);
protected void Connect (string name, Delegate cb, int flags)
{
_HandlerID = g_signal_connect_data(_obj.Handle, name, cb, _key, new IntPtr(0), flags);
}
[DllImport("libgobject-2.0-0.dll")]
static extern void g_signal_handler_disconnect (IntPtr instance, uint handler);
[DllImport("libgobject-2.0-0.dll")]
static extern bool g_signal_handler_is_connected (IntPtr instance, uint handler);
protected void Disconnect ()
{
if (g_signal_handler_is_connected (_obj.Handle, _HandlerID))
g_signal_handler_disconnect (_obj.Handle, _HandlerID);
}
public void Dispose ()
{
Dispose (true);

View file

@ -20,7 +20,7 @@ namespace Gnome {
public event UpdateHandler Update {
add {
if (AfterHandlers["update"] == null)
AfterSignals["update"] = new GtkSharp.voidObjectAffineSVPintSignal(this, Handle, "update", value, System.Type.GetType("EventArgs"));
AfterSignals["update"] = new GtkSharp.voidObjectAffineSVPintSignal(this, "update", value, System.Type.GetType("EventArgs"));
AfterHandlers.AddHandler("update", value);
}
@ -34,7 +34,7 @@ namespace Gnome {
public event EventHandler Realize {
add {
if (AfterHandlers["realize"] == null)
AfterSignals["realize"] = new GnomeSharp.voidObjectSignal(this, Handle, "realize", value, System.Type.GetType("EventArgs"), 1);
AfterSignals["realize"] = new GnomeSharp.voidObjectSignal(this, "realize", value, System.Type.GetType("EventArgs"), 1);
AfterHandlers.AddHandler("realize", value);
}
remove {
@ -47,7 +47,7 @@ namespace Gnome {
public event EventHandler Unrealize {
add {
if (AfterHandlers["unrealize"] == null)
AfterSignals["unrealize"] = new GnomeSharp.voidObjectSignal(this, Handle, "unrealize", value, System.Type.GetType("EventArgs"), 1);
AfterSignals["unrealize"] = new GnomeSharp.voidObjectSignal(this, "unrealize", value, System.Type.GetType("EventArgs"), 1);
AfterHandlers.AddHandler("unrealize", value);
}
remove {
@ -60,7 +60,7 @@ namespace Gnome {
public event EventHandler Map {
add {
if (AfterHandlers["map"] == null)
AfterSignals["map"] = new GnomeSharp.voidObjectSignal(this, Handle, "map", value, System.Type.GetType("EventArgs"), 1);
AfterSignals["map"] = new GnomeSharp.voidObjectSignal(this, "map", value, System.Type.GetType("EventArgs"), 1);
AfterHandlers.AddHandler("map", value);
}
remove {
@ -73,7 +73,7 @@ namespace Gnome {
public event EventHandler Unmap {
add {
if (AfterHandlers["unmap"] == null)
AfterSignals["unmap"] = new GnomeSharp.voidObjectSignal(this, Handle, "unmap", value, System.Type.GetType("EventArgs"), 1);
AfterSignals["unmap"] = new GnomeSharp.voidObjectSignal(this, "unmap", value, System.Type.GetType("EventArgs"), 1);
AfterHandlers.AddHandler("unmap", value);
}
remove {

View file

@ -10,19 +10,9 @@ namespace Gnome {
using System;
/// <summary> BoundsHandler Delegate </summary>
/// <remarks>
/// Delegate signature for Bounds Event handlers
/// </remarks>
public delegate void BoundsHandler(object o, BoundsArgs args);
/// <summary> BoundsArgs Class </summary>
/// <remarks>
/// Arguments for Bounds Event handlers
/// </remarks>
public class BoundsArgs : GtkSharp.SignalArgs {
public class BoundsArgs : GLib.SignalArgs {
public double [] X1 {
get {

View file

@ -10,19 +10,9 @@ namespace Gnome {
using System;
/// <summary> DrawHandler Delegate </summary>
/// <remarks>
/// Delegate signature for Draw Event handlers
/// </remarks>
public delegate void DrawHandler(object o, DrawArgs args);
/// <summary> DrawArgs Class </summary>
/// <remarks>
/// Arguments for Draw Event handlers
/// </remarks>
public class DrawArgs : GtkSharp.SignalArgs {
public class DrawArgs : GLib.SignalArgs {
public Gdk.Drawable Drawable {
get {

View file

@ -10,19 +10,9 @@ namespace Gnome {
using System;
/// <summary> PointHandler Delegate </summary>
/// <remarks>
/// Delegate signature for Point Event handlers
/// </remarks>
public delegate void PointHandler(object o, PointArgs args);
/// <summary> PointArgs Class </summary>
/// <remarks>
/// Arguments for Point Event handlers
/// </remarks>
public class PointArgs : GtkSharp.SignalArgs {
public class PointArgs : GLib.SignalArgs {
public double X {
get {

View file

@ -10,19 +10,9 @@ namespace Gnome {
using System;
/// <summary> RenderHandler Delegate </summary>
/// <remarks>
/// Delegate signature for Render Event handlers
/// </remarks>
public delegate void RenderHandler(object o, RenderArgs args);
/// <summary> RenderArgs Class </summary>
/// <remarks>
/// Arguments for Render Event handlers
/// </remarks>
public class RenderArgs : GtkSharp.SignalArgs {
public class RenderArgs : GLib.SignalArgs {
public Gnome.CanvasBuf Buf {
get {

View file

@ -10,19 +10,9 @@ namespace Gnome {
using System;
/// <summary> CanvasUpdateHandler Delegate </summary>
/// <remarks>
/// Delegate signature for CanvasUpdate Event handlers
/// </remarks>
public delegate void UpdateHandler (object o, UpdateArgs args);
/// <summary> CanvasUpdateArgs Class </summary>
/// <remarks>
/// Arguments for CanvasUpdate Event handlers
/// </remarks>
public class UpdateArgs : GtkSharp.SignalArgs {
public class UpdateArgs : GLib.SignalArgs {
public double [] Affine {
get {

View file

@ -7,7 +7,7 @@ namespace GtkSharp {
internal delegate void voidObjectAffineSVPintDelegate(IntPtr arg0, IntPtr arg1, ref Art.SVP arg2, int arg3, int key);
internal class voidObjectAffineSVPintSignal : SignalCallback {
internal class voidObjectAffineSVPintSignal : GLib.SignalCallback {
private static voidObjectAffineSVPintDelegate _Delegate;
@ -17,7 +17,7 @@ namespace GtkSharp {
throw new Exception("Unexpected signal key " + key);
voidObjectAffineSVPintSignal inst = (voidObjectAffineSVPintSignal) _Instances[key];
SignalArgs args = (SignalArgs) Activator.CreateInstance (inst._argstype);
GLib.SignalArgs args = (GLib.SignalArgs) Activator.CreateInstance (inst._argstype);
args.Args = new object[3];
if (arg1 != IntPtr.Zero) {
double[] affine = new double[6];
@ -38,12 +38,12 @@ namespace GtkSharp {
[DllImport("libgobject-2.0-0.dll")] static extern void g_signal_connect_data(IntPtr obj, String name, voidObjectAffineSVPintDelegate cb, int key, IntPtr p, int flags);
public voidObjectAffineSVPintSignal(GLib.Object obj, IntPtr raw, String name, MulticastDelegate eh, Type argstype) : base(obj, eh, argstype)
public voidObjectAffineSVPintSignal(GLib.Object obj, String name, MulticastDelegate eh, Type argstype) : base(obj, eh, argstype)
{
if (_Delegate == null) {
_Delegate = new voidObjectAffineSVPintDelegate(voidObjectAffineSVPintCallback);
}
g_signal_connect_data(raw, name, _Delegate, _key, new IntPtr(0), 0);
g_signal_connect_data(_obj.Handle, name, _Delegate, _key, new IntPtr(0), 0);
}
~voidObjectAffineSVPintSignal()