From 1a1f5e1702dd7b9b67ef4973577f48e806e83d7b Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Tue, 16 Mar 2004 19:43:04 +0000 Subject: [PATCH] 2004-03-16 Mike Kestner * generator/ObjectGen.cs : don't gen a Signals hash per class. * generator/Signal.cs : gen checks for [ConnectBefore]. * generator/SignalHandler.cs : add connect_flags param to ctor. * glib/ConnectBeforeAttribute.cs : new attr * glib/Makefile.am : add new file * glib/Object.cs : add before/after hashes and EventLists * gnome/CanvasProxy.cs : use AfterSignals and AfterHandlers. svn path=/trunk/gtk-sharp/; revision=24157 --- ChangeLog | 10 ++ generator/ObjectGen.cs | 4 +- generator/Signal.cs | 46 ++++++-- generator/SignalHandler.cs | 7 +- glib/ConnectBeforeAttribute.cs | 15 +++ glib/Makefile.am | 1 + glib/Object.cs | 201 ++++++--------------------------- gnome/CanvasProxy.cs | 92 ++++++++------- 8 files changed, 149 insertions(+), 227 deletions(-) create mode 100644 glib/ConnectBeforeAttribute.cs diff --git a/ChangeLog b/ChangeLog index d15392b27..669996a28 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-03-16 Mike Kestner + + * generator/ObjectGen.cs : don't gen a Signals hash per class. + * generator/Signal.cs : gen checks for [ConnectBefore]. + * generator/SignalHandler.cs : add connect_flags param to ctor. + * glib/ConnectBeforeAttribute.cs : new attr + * glib/Makefile.am : add new file + * glib/Object.cs : add before/after hashes and EventLists + * gnome/CanvasProxy.cs : use AfterSignals and AfterHandlers. + 2004-03-14 John Luke * parser/gapi-fixup.in: diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index 6bcbd7ec7..19a644c91 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -124,9 +124,7 @@ namespace GtkSharp.Generation { } } - if (has_sigs && Elem.HasAttribute("parent")) - { - sw.WriteLine("\t\tprivate Hashtable Signals = new Hashtable();\n"); + if (has_sigs && Elem.HasAttribute("parent")) { GenSignals (gen_info, null); } diff --git a/generator/Signal.cs b/generator/Signal.cs index 93fcd2b75..62b02c745 100644 --- a/generator/Signal.cs +++ b/generator/Signal.cs @@ -2,7 +2,8 @@ // // Author: Mike Kestner // -// (c) 2001-2003 Mike Kestner, (c) 2003 Novell, Inc. +// (c) 2001-2003 Mike Kestner +// (c) 2003-2004 Novell, Inc. namespace GtkSharp.Generation { @@ -247,25 +248,50 @@ namespace GtkSharp.Generation { sw.Write("new "); sw.WriteLine("event " + EventHandlerQualifiedName + " " + Name + " {"); sw.WriteLine("\t\t\tadd {"); - sw.WriteLine("\t\t\t\tif (EventList[" + cname + "] == null)"); - sw.Write("\t\t\t\t\tSignals[" + cname + "] = new " + qual_marsh); + sw.WriteLine("\t\t\t\tif (value.Method.GetCustomAttributes(typeof(GLib.ConnectBeforeAttribute), false).Length > 0) {"); + sw.WriteLine("\t\t\t\t\tConsole.WriteLine (\"Connecting before: " + Name + "\");"); + 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); if (EventArgsQualifiedName != "System.EventArgs") sw.Write("," + gen_info.AssemblyName); - sw.WriteLine("\"));\n\t\t\t\telse"); - sw.WriteLine("\t\t\t\t\t((GtkSharp.SignalCallback) Signals [{0}]).AddDelegate (value);", cname); - sw.WriteLine("\t\t\t\tEventList.AddHandler(" + cname + ", value);"); + 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\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); + 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\tAfterHandlers.AddHandler(" + cname + ", value);"); + sw.WriteLine("\t\t\t\t}"); sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t\tremove {"); - sw.WriteLine("\t\t\t\tEventList.RemoveHandler(" + cname + ", value);"); - sw.WriteLine("\t\t\t\tGtkSharp.SignalCallback cb = Signals [{0}] as GtkSharp.SignalCallback;", cname); + sw.WriteLine("\t\t\t\tGtkSharp.SignalCallback cb = null;"); + sw.WriteLine("\t\t\t\tSystem.ComponentModel.EventHandlerList event_list = null;"); + sw.WriteLine("\t\t\t\tHashtable signals = null;"); + sw.WriteLine("\t\t\t\tif (value.Method.GetCustomAttributes(typeof(GLib.ConnectBeforeAttribute), false).Length > 0) {"); + sw.WriteLine("\t\t\t\t\tcb = BeforeSignals [{0}] as GtkSharp.SignalCallback;", cname); + sw.WriteLine("\t\t\t\t\tevent_list = BeforeHandlers;"); + sw.WriteLine("\t\t\t\t\tsignals = BeforeSignals;"); + sw.WriteLine("\t\t\t\t} else {"); + sw.WriteLine("\t\t\t\t\tcb = AfterSignals [{0}] as GtkSharp.SignalCallback;", cname); + sw.WriteLine("\t\t\t\t\tevent_list = AfterHandlers;"); + sw.WriteLine("\t\t\t\t\tsignals = AfterSignals;"); + sw.WriteLine("\t\t\t\t}"); + 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;"); sw.WriteLine(); sw.WriteLine("\t\t\t\tcb.RemoveDelegate (value);"); sw.WriteLine(); - sw.WriteLine("\t\t\t\tif (EventList[" + cname + "] == null) {"); - sw.WriteLine("\t\t\t\t\tSignals.Remove(" + cname + ");"); + sw.WriteLine("\t\t\t\tif (event_list[" + cname + "] == null) {"); + sw.WriteLine("\t\t\t\t\tsignals.Remove(" + cname + ");"); sw.WriteLine("\t\t\t\t\tcb.Dispose ();"); sw.WriteLine("\t\t\t\t}"); sw.WriteLine("\t\t\t}"); diff --git a/generator/SignalHandler.cs b/generator/SignalHandler.cs index b4086ff0f..645f27d87 100644 --- a/generator/SignalHandler.cs +++ b/generator/SignalHandler.cs @@ -1,8 +1,9 @@ // GtkSharp.Generation.SignalHandler.cs - The SignalHandler marshaling Class. // -// Author: Mike Kestner +// Author: Mike Kestner // // (c) 2002-2003 Mike Kestner +// (c) 2004 Novell, Inc. namespace GtkSharp.Generation { @@ -184,14 +185,14 @@ namespace GtkSharp.Generation { sw.WriteLine(" int flags);"); sw.WriteLine(); sw.Write("\t\tpublic " + Name + "(GLib.Object obj, IntPtr raw, "); - sw.WriteLine("string name, Delegate eh, Type argstype) : base(obj, eh, argstype)"); + 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), 1);"); + sw.WriteLine("_Delegate, _key, new IntPtr(0), connect_flags);"); sw.WriteLine("\t\t}"); sw.WriteLine(); sw.WriteLine("\t\t[DllImport(\"libgobject-2.0-0.dll\")]"); diff --git a/glib/ConnectBeforeAttribute.cs b/glib/ConnectBeforeAttribute.cs new file mode 100644 index 000000000..e0e781d10 --- /dev/null +++ b/glib/ConnectBeforeAttribute.cs @@ -0,0 +1,15 @@ +// ConnectBeforeAttribute.cs +// +// Author: Mike Kestner +// +// (C) 2004 Novell, Inc. + +namespace GLib { + + using System; + + public sealed class ConnectBeforeAttribute : Attribute + { + public ConnectBeforeAttribute () {} + } +} diff --git a/glib/Makefile.am b/glib/Makefile.am index 653cddb48..a790bf426 100644 --- a/glib/Makefile.am +++ b/glib/Makefile.am @@ -9,6 +9,7 @@ references = sources = \ Boxed.cs \ + ConnectBeforeAttribute.cs \ DefaultSignalHandlerAttribute.cs \ DelegateWrapper.cs \ EnumWrapper.cs \ diff --git a/glib/Object.cs b/glib/Object.cs index a4630ed3e..7a300576a 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -3,10 +3,8 @@ // Authors: Mike Kestner // // (c) 2001-2003 Mike Kestner -// -// TODO: -// Could remove `disposed' for a check if an object is on the dispose_queue_list. -// +// (c) 2004 Novell, Inc. + namespace GLib { using System; @@ -15,28 +13,15 @@ namespace GLib { using System.Reflection; using System.Runtime.InteropServices; - /// - /// Object Class - /// - /// - /// - /// Wrapper class for GObject. - /// - public class Object : IWrapper, IDisposable { - // Private class and instance members IntPtr _obj; - EventHandlerList _events; bool disposed = false; Hashtable data; static Hashtable Objects = new Hashtable(); static Queue PendingDestroys = new Queue (); static bool idle_queued; - // - // The destructor is invoked by a thread - // ~Object () { Dispose (); @@ -67,16 +52,6 @@ namespace GLib { return false; } - /// - /// Dispose Method - /// - /// - /// - /// Disposes of the raw object. Only override this if - /// the Raw object should not be unref'd when the object - /// is garbage collected. - /// - public void Dispose () { if (disposed) @@ -99,22 +74,6 @@ namespace GLib { [DllImport("libgobject-2.0-0.dll")] static extern void g_object_ref (IntPtr raw); - /// - /// GetObject Shared Method - /// - /// - /// - /// Used to obtain a CLI typed object associated with a - /// given raw object pointer. This method is primarily - /// used to wrap object references that are returned - /// by either the signal system or raw class methods that - /// return GObject references. - /// - /// - /// - /// The wrapper instance. - /// - public static Object GetObject(IntPtr o, bool owned_ref) { Object obj; @@ -166,16 +125,6 @@ namespace GLib { [DllImport("glibsharpglue")] static extern IntPtr gtksharp_register_type (string name, IntPtr parent_type); - /// - /// RegisterGType Shared Method - /// - /// - /// - /// Shared method to register types with the GType system. - /// This method should be called from the class constructor - /// of subclasses. - /// - public static GType RegisterGType (System.Type t) { System.Type parent = t.BaseType; @@ -192,24 +141,8 @@ namespace GLib { return gtype; } - /// - /// Object Constructor - /// - /// - /// - /// Dummy constructor needed for derived classes. - /// - protected Object () {} - /// - /// Object Constructor - /// - /// - /// - /// Creates an object from a raw object reference. - /// - public Object (IntPtr raw) { Raw = raw; @@ -218,30 +151,11 @@ namespace GLib { [DllImport("libgobject-2.0-0.dll")] static extern IntPtr g_object_new (IntPtr gtype, IntPtr dummy); - /// - /// Object Constructor - /// - /// - /// - /// Creates an object from a specified GType. - /// - protected Object (GType gtype) { Raw = g_object_new (gtype.Val, IntPtr.Zero); } - /// - /// Raw Property - /// - /// - /// - /// The raw GObject reference associated with this wrapper. - /// Only subclasses of Object can access this read/write - /// property. For public read-only access, use the - /// Handle property. - /// - protected virtual IntPtr Raw { get { return _obj; @@ -252,14 +166,6 @@ namespace GLib { } } - /// - /// GType Property - /// - /// - /// - /// The type associated with this object class. - /// - [DllImport("glibsharpglue")] private static extern IntPtr gtksharp_get_type_id (IntPtr obj); @@ -278,14 +184,6 @@ namespace GLib { } } - /// - /// GetGType Method - /// - /// - /// - /// Returns the GType of this object. - /// - public GLib.GType GetGType () { if (_obj == IntPtr.Zero) return GType.Invalid; @@ -293,60 +191,53 @@ namespace GLib { return new GLib.GType (gtksharp_get_type_id (_obj)); } - /// - /// Handle Property - /// - /// - /// - /// The raw GObject reference associated with this object. - /// Subclasses can use Raw property for read/write - /// access. - /// - public IntPtr Handle { get { return _obj; } } - /// - /// EventList Property - /// - /// - /// - /// A list object containing all the events for this - /// object indexed by the Gtk+ signal name. - /// - - protected EventHandlerList EventList { + Hashtable before_signals; + protected Hashtable BeforeSignals { get { - if (_events == null) - _events = new EventHandlerList (); - return _events; + if (before_signals == null) + before_signals = new Hashtable (); + return before_signals; } } - /// - /// GetHashCode Method - /// - /// - /// - /// Calculates a hashing value. - /// + Hashtable after_signals; + protected Hashtable AfterSignals { + get { + if (after_signals == null) + after_signals = new Hashtable (); + return after_signals; + } + } + + EventHandlerList before_handlers; + protected EventHandlerList BeforeHandlers { + get { + if (before_handlers == null) + before_handlers = new EventHandlerList (); + return before_handlers; + } + } + + EventHandlerList after_handlers; + protected EventHandlerList AfterHandlers { + get { + if (after_handlers == null) + after_handlers = new EventHandlerList (); + return after_handlers; + } + } public override int GetHashCode () { return Handle.GetHashCode (); } - /// - /// Data property - /// - /// - /// - /// Stores and Accesses arbitrary data on the Object. - /// - public Hashtable Data { get { if (data == null) @@ -357,35 +248,17 @@ namespace GLib { } [DllImport("libgobject-2.0-0.dll")] - static extern void g_object_get_property ( - IntPtr obj, string name, IntPtr val); + static extern void g_object_get_property (IntPtr obj, string name, IntPtr val); - /// - /// GetProperty Method - /// - /// - /// - /// Accesses a Value Property. - /// - - public void GetProperty (String name, GLib.Value val) + protected void GetProperty (String name, GLib.Value val) { g_object_get_property (Raw, name, val.Handle); } [DllImport("libgobject-2.0-0.dll")] - static extern void g_object_set_property ( - IntPtr obj, string name, IntPtr val); + static extern void g_object_set_property (IntPtr obj, string name, IntPtr val); - /// - /// SetProperty Method - /// - /// - /// - /// Accesses a Value Property. - /// - - public void SetProperty (String name, GLib.Value val) + protected void SetProperty (String name, GLib.Value val) { g_object_set_property (Raw, name, val.Handle); } diff --git a/gnome/CanvasProxy.cs b/gnome/CanvasProxy.cs index dc568fbe6..41d54b74d 100644 --- a/gnome/CanvasProxy.cs +++ b/gnome/CanvasProxy.cs @@ -22,71 +22,69 @@ namespace Gnome { { } - private Hashtable Signals = new Hashtable (); - public event UpdateHandler Update { add { - if (EventList["update"] == null) - Signals["update"] = new GtkSharp.voidObjectAffineSVPintSignal(this, Handle, "update", value, System.Type.GetType("EventArgs")); - EventList.AddHandler("update", value); + if (AfterHandlers["update"] == null) + AfterSignals["update"] = new GtkSharp.voidObjectAffineSVPintSignal(this, Handle, "update", value, System.Type.GetType("EventArgs")); + AfterHandlers.AddHandler("update", value); } remove { - EventList.RemoveHandler ("update", value); - if (EventList ["update"] == null) - Signals.Remove ("update"); + AfterHandlers.RemoveHandler ("update", value); + if (AfterHandlers ["update"] == null) + AfterSignals.Remove ("update"); } } public event EventHandler Realize { add { - if (EventList["realize"] == null) - Signals["realize"] = new GnomeSharp.voidObjectSignal(this, Handle, "realize", value, System.Type.GetType("EventArgs")); - EventList.AddHandler("realize", value); + if (AfterHandlers["realize"] == null) + AfterSignals["realize"] = new GnomeSharp.voidObjectSignal(this, Handle, "realize", value, System.Type.GetType("EventArgs"), 1); + AfterHandlers.AddHandler("realize", value); } remove { - EventList.RemoveHandler("realize", value); - if (EventList["realize"] == null) - Signals.Remove("realize"); + AfterHandlers.RemoveHandler("realize", value); + if (AfterHandlers["realize"] == null) + AfterSignals.Remove("realize"); } } public event EventHandler Unrealize { add { - if (EventList["unrealize"] == null) - Signals["unrealize"] = new GnomeSharp.voidObjectSignal(this, Handle, "unrealize", value, System.Type.GetType("EventArgs")); - EventList.AddHandler("unrealize", value); + if (AfterHandlers["unrealize"] == null) + AfterSignals["unrealize"] = new GnomeSharp.voidObjectSignal(this, Handle, "unrealize", value, System.Type.GetType("EventArgs"), 1); + AfterHandlers.AddHandler("unrealize", value); } remove { - EventList.RemoveHandler("unrealize", value); - if (EventList["unrealize"] == null) - Signals.Remove("unrealize"); + AfterHandlers.RemoveHandler("unrealize", value); + if (AfterHandlers["unrealize"] == null) + AfterSignals.Remove("unrealize"); } } public event EventHandler Map { add { - if (EventList["map"] == null) - Signals["map"] = new GnomeSharp.voidObjectSignal(this, Handle, "map", value, System.Type.GetType("EventArgs")); - EventList.AddHandler("map", value); + if (AfterHandlers["map"] == null) + AfterSignals["map"] = new GnomeSharp.voidObjectSignal(this, Handle, "map", value, System.Type.GetType("EventArgs"), 1); + AfterHandlers.AddHandler("map", value); } remove { - EventList.RemoveHandler("map", value); - if (EventList["map"] == null) - Signals.Remove("map"); + AfterHandlers.RemoveHandler("map", value); + if (AfterHandlers["map"] == null) + AfterSignals.Remove("map"); } } public event EventHandler Unmap { add { - if (EventList["unmap"] == null) - Signals["unmap"] = new GnomeSharp.voidObjectSignal(this, Handle, "unmap", value, System.Type.GetType("EventArgs")); - EventList.AddHandler("unmap", value); + if (AfterHandlers["unmap"] == null) + AfterSignals["unmap"] = new GnomeSharp.voidObjectSignal(this, Handle, "unmap", value, System.Type.GetType("EventArgs"), 1); + AfterHandlers.AddHandler("unmap", value); } remove { - EventList.RemoveHandler("unmap", value); - if (EventList["unmap"] == null) - Signals.Remove("unmap"); + AfterHandlers.RemoveHandler("unmap", value); + if (AfterHandlers["unmap"] == null) + AfterSignals.Remove("unmap"); } } @@ -96,9 +94,9 @@ namespace Gnome { } remove { - EventList.RemoveHandler ("coverage", value); - if (EventList ["coverage"] == null) - Signals.Remove ("coverage"); + AfterHandlers.RemoveHandler ("coverage", value); + if (AfterHandlers ["coverage"] == null) + AfterSignals.Remove ("coverage"); } } @@ -109,9 +107,9 @@ namespace Gnome { } remove { - EventList.RemoveHandler ("draw", value); - if (EventList ["draw"] == null) - Signals.Remove ("draw"); + AfterHandlers.RemoveHandler ("draw", value); + if (AfterHandlers ["draw"] == null) + AfterSignals.Remove ("draw"); } } @@ -121,9 +119,9 @@ namespace Gnome { } remove { - EventList.RemoveHandler ("render", value); - if (EventList ["render"] == null) - Signals.Remove ("render"); + AfterHandlers.RemoveHandler ("render", value); + if (AfterHandlers ["render"] == null) + AfterSignals.Remove ("render"); } } @@ -133,9 +131,9 @@ namespace Gnome { } remove { - EventList.RemoveHandler ("point", value); - if (EventList ["point"] == null) - Signals.Remove ("point"); + AfterHandlers.RemoveHandler ("point", value); + if (AfterHandlers ["point"] == null) + AfterSignals.Remove ("point"); } } @@ -145,9 +143,9 @@ namespace Gnome { } remove { - EventList.RemoveHandler ("bounds", value); - if (EventList ["bounds"] == null) - Signals.Remove ("bounds"); + AfterHandlers.RemoveHandler ("bounds", value); + if (AfterHandlers ["bounds"] == null) + AfterSignals.Remove ("bounds"); } } }