From 01acd7f5766b1f301441d267e88ccc1bcd92f8bd Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Wed, 5 May 2004 18:24:04 +0000 Subject: [PATCH] 2004-05-05 Mike Kestner * 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 --- ChangeLog | 17 ++++++++- generator/Signal.cs | 12 +++--- generator/SignalHandler.cs | 28 +++----------- glib/SignalArgs.cs | 55 +-------------------------- glib/SignalCallback.cs | 47 +++++++++++++---------- gnome/CanvasProxy.cs | 10 ++--- gnome/GtkSharp.BoundsHandler.cs | 12 +----- gnome/GtkSharp.DrawHandler.cs | 12 +----- gnome/GtkSharp.PointHandler.cs | 12 +----- gnome/GtkSharp.RenderHandler.cs | 12 +----- gnome/GtkSharp.UpdateHandler.cs | 12 +----- gnome/voidObjectAffineSVPintSignal.cs | 8 ++-- 12 files changed, 69 insertions(+), 168 deletions(-) diff --git a/ChangeLog b/ChangeLog index ad346334d..a3d7ef682 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,23 @@ 2004-05-05 Mike Kestner + * 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 + * sample/gconf/Makefile.am : fix some whitespace. I love you, auto*. -2004-05-05 Mike Kestner +2004-05-04 Mike Kestner * configure.in : fix gtkhtml versioning *again*. * sample/gconf/Makefile.am : conditional build on ENABLE_GNOME. diff --git a/generator/Signal.cs b/generator/Signal.cs index 1fcc17ce6..465acb4a6 100644 --- a/generator/Signal.cs +++ b/generator/Signal.cs @@ -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;"); diff --git a/generator/SignalHandler.cs b/generator/SignalHandler.cs index 645f27d87..cb36523da 100644 --- a/generator/SignalHandler.cs +++ b/generator/SignalHandler.cs @@ -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}"); diff --git a/glib/SignalArgs.cs b/glib/SignalArgs.cs index eeed49445..2345702e6 100644 --- a/glib/SignalArgs.cs +++ b/glib/SignalArgs.cs @@ -1,79 +1,36 @@ -// GtkSharp.SignalArgs.cs - Signal argument class implementation +// GLib.SignalArgs.cs - Signal argument class implementation // // Author: Mike Kestner // // (c) 2001 Mike Kestner -namespace GtkSharp { +namespace GLib { using System; using System.Collections; - /// - /// SignalArgs Class - /// - /// - /// - /// Arguments and return value for signals. - /// - public class SignalArgs : EventArgs { private object _ret; private object[] _args; - /// - /// SignalArgs Constructor - /// - /// - /// - /// Creates a SignalArgs object with no return value and - /// no arguments. - /// - public SignalArgs() { _ret = null; _args = null; } - /// - /// SignalArgs Constructor - /// - /// - /// - /// Creates a SignalArgs object with a return value and - /// no arguments. - /// - public SignalArgs(object retval) { _ret = retval; _args = null; } - /// - /// SignalArgs Constructor - /// - /// - /// - /// Creates a SignalArgs object with a return value and - /// a list of arguments. - /// - public SignalArgs(object retval, object[] args) { _ret = retval; _args = args; } - /// - /// Args Property - /// - /// - /// - /// A list of arguments. - /// - public object[] Args { get { return _args; @@ -83,14 +40,6 @@ namespace GtkSharp { } } - /// - /// RetVal Property - /// - /// - /// - /// The return value. - /// - public object RetVal { get { return _ret; diff --git a/glib/SignalCallback.cs b/glib/SignalCallback.cs index 463bbe717..b98c61842 100644 --- a/glib/SignalCallback.cs +++ b/glib/SignalCallback.cs @@ -1,22 +1,14 @@ -// GtkSharp.SignalCallback.cs - Signal callback base class implementation +// GLib.SignalCallback.cs - Signal callback base class implementation // -// Authors: Mike Kestner +// Authors: Mike Kestner // -// (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; - - /// - /// SignalCallback Class - /// - /// - /// - /// Base Class for GSignal to C# event marshalling. - /// public abstract class SignalCallback : IDisposable { @@ -31,14 +23,7 @@ namespace GtkSharp { protected Delegate _handler; protected int _key; protected System.Type _argstype; - - /// - /// SignalCallback Constructor - /// - /// - /// - /// Initializes instance data. - /// + 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); diff --git a/gnome/CanvasProxy.cs b/gnome/CanvasProxy.cs index 10397a872..60cd23460 100644 --- a/gnome/CanvasProxy.cs +++ b/gnome/CanvasProxy.cs @@ -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 { diff --git a/gnome/GtkSharp.BoundsHandler.cs b/gnome/GtkSharp.BoundsHandler.cs index 70b7cf28e..b97d7cdda 100644 --- a/gnome/GtkSharp.BoundsHandler.cs +++ b/gnome/GtkSharp.BoundsHandler.cs @@ -10,19 +10,9 @@ namespace Gnome { using System; - /// BoundsHandler Delegate - /// - /// Delegate signature for Bounds Event handlers - /// - public delegate void BoundsHandler(object o, BoundsArgs args); - /// BoundsArgs Class - /// - /// Arguments for Bounds Event handlers - /// - - public class BoundsArgs : GtkSharp.SignalArgs { + public class BoundsArgs : GLib.SignalArgs { public double [] X1 { get { diff --git a/gnome/GtkSharp.DrawHandler.cs b/gnome/GtkSharp.DrawHandler.cs index 4a16ffafe..eb8c57199 100644 --- a/gnome/GtkSharp.DrawHandler.cs +++ b/gnome/GtkSharp.DrawHandler.cs @@ -10,19 +10,9 @@ namespace Gnome { using System; - /// DrawHandler Delegate - /// - /// Delegate signature for Draw Event handlers - /// - public delegate void DrawHandler(object o, DrawArgs args); - /// DrawArgs Class - /// - /// Arguments for Draw Event handlers - /// - - public class DrawArgs : GtkSharp.SignalArgs { + public class DrawArgs : GLib.SignalArgs { public Gdk.Drawable Drawable { get { diff --git a/gnome/GtkSharp.PointHandler.cs b/gnome/GtkSharp.PointHandler.cs index d7126dbc3..2fb097c12 100644 --- a/gnome/GtkSharp.PointHandler.cs +++ b/gnome/GtkSharp.PointHandler.cs @@ -10,19 +10,9 @@ namespace Gnome { using System; - /// PointHandler Delegate - /// - /// Delegate signature for Point Event handlers - /// - public delegate void PointHandler(object o, PointArgs args); - /// PointArgs Class - /// - /// Arguments for Point Event handlers - /// - - public class PointArgs : GtkSharp.SignalArgs { + public class PointArgs : GLib.SignalArgs { public double X { get { diff --git a/gnome/GtkSharp.RenderHandler.cs b/gnome/GtkSharp.RenderHandler.cs index 1340464bf..416a936d4 100644 --- a/gnome/GtkSharp.RenderHandler.cs +++ b/gnome/GtkSharp.RenderHandler.cs @@ -10,19 +10,9 @@ namespace Gnome { using System; - /// RenderHandler Delegate - /// - /// Delegate signature for Render Event handlers - /// - public delegate void RenderHandler(object o, RenderArgs args); - /// RenderArgs Class - /// - /// Arguments for Render Event handlers - /// - - public class RenderArgs : GtkSharp.SignalArgs { + public class RenderArgs : GLib.SignalArgs { public Gnome.CanvasBuf Buf { get { diff --git a/gnome/GtkSharp.UpdateHandler.cs b/gnome/GtkSharp.UpdateHandler.cs index 428c20dc9..1ff0bb588 100644 --- a/gnome/GtkSharp.UpdateHandler.cs +++ b/gnome/GtkSharp.UpdateHandler.cs @@ -10,19 +10,9 @@ namespace Gnome { using System; - /// CanvasUpdateHandler Delegate - /// - /// Delegate signature for CanvasUpdate Event handlers - /// - public delegate void UpdateHandler (object o, UpdateArgs args); - /// CanvasUpdateArgs Class - /// - /// Arguments for CanvasUpdate Event handlers - /// - - public class UpdateArgs : GtkSharp.SignalArgs { + public class UpdateArgs : GLib.SignalArgs { public double [] Affine { get { diff --git a/gnome/voidObjectAffineSVPintSignal.cs b/gnome/voidObjectAffineSVPintSignal.cs index 24b5448a8..7edbb6ca3 100644 --- a/gnome/voidObjectAffineSVPintSignal.cs +++ b/gnome/voidObjectAffineSVPintSignal.cs @@ -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()