2004-03-16 Mike Kestner <mkestner@ximian.com>

* 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
This commit is contained in:
Mike Kestner 2004-03-16 19:43:04 +00:00
parent 5e03bca76f
commit 1a1f5e1702
8 changed files with 149 additions and 227 deletions

View file

@ -1,3 +1,13 @@
2004-03-16 Mike Kestner <mkestner@ximian.com>
* 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 <jluke@cfl.rr.com>
* parser/gapi-fixup.in:

View file

@ -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);
}

View file

@ -2,7 +2,8 @@
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (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}");

View file

@ -1,8 +1,9 @@
// GtkSharp.Generation.SignalHandler.cs - The SignalHandler marshaling Class.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
// Author: Mike Kestner <mkestner@ximian.com>
//
// (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\")]");

View file

@ -0,0 +1,15 @@
// ConnectBeforeAttribute.cs
//
// Author: Mike Kestner <mkestner@ximian.com>
//
// (C) 2004 Novell, Inc.
namespace GLib {
using System;
public sealed class ConnectBeforeAttribute : Attribute
{
public ConnectBeforeAttribute () {}
}
}

View file

@ -9,6 +9,7 @@ references =
sources = \
Boxed.cs \
ConnectBeforeAttribute.cs \
DefaultSignalHandlerAttribute.cs \
DelegateWrapper.cs \
EnumWrapper.cs \

View file

@ -3,10 +3,8 @@
// Authors: Mike Kestner <mkestner@speakeasy.net>
//
// (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;
/// <summary>
/// Object Class
/// </summary>
///
/// <remarks>
/// Wrapper class for GObject.
/// </remarks>
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;
}
/// <summary>
/// Dispose Method
/// </summary>
///
/// <remarks>
/// Disposes of the raw object. Only override this if
/// the Raw object should not be unref'd when the object
/// is garbage collected.
/// </remarks>
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);
/// <summary>
/// GetObject Shared Method
/// </summary>
///
/// <remarks>
/// 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.
/// </remarks>
///
/// <returns>
/// The wrapper instance.
/// </returns>
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);
/// <summary>
/// RegisterGType Shared Method
/// </summary>
///
/// <remarks>
/// Shared method to register types with the GType system.
/// This method should be called from the class constructor
/// of subclasses.
/// </remarks>
public static GType RegisterGType (System.Type t)
{
System.Type parent = t.BaseType;
@ -192,24 +141,8 @@ namespace GLib {
return gtype;
}
/// <summary>
/// Object Constructor
/// </summary>
///
/// <remarks>
/// Dummy constructor needed for derived classes.
/// </remarks>
protected Object () {}
/// <summary>
/// Object Constructor
/// </summary>
///
/// <remarks>
/// Creates an object from a raw object reference.
/// </remarks>
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);
/// <summary>
/// Object Constructor
/// </summary>
///
/// <remarks>
/// Creates an object from a specified GType.
/// </remarks>
protected Object (GType gtype)
{
Raw = g_object_new (gtype.Val, IntPtr.Zero);
}
/// <summary>
/// Raw Property
/// </summary>
///
/// <remarks>
/// 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.
/// </remarks>
protected virtual IntPtr Raw {
get {
return _obj;
@ -252,14 +166,6 @@ namespace GLib {
}
}
/// <summary>
/// GType Property
/// </summary>
///
/// <remarks>
/// The type associated with this object class.
/// </remarks>
[DllImport("glibsharpglue")]
private static extern IntPtr gtksharp_get_type_id (IntPtr obj);
@ -278,14 +184,6 @@ namespace GLib {
}
}
/// <summary>
/// GetGType Method
/// </summary>
///
/// <remarks>
/// Returns the GType of this object.
/// </remarks>
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));
}
/// <summary>
/// Handle Property
/// </summary>
///
/// <remarks>
/// The raw GObject reference associated with this object.
/// Subclasses can use Raw property for read/write
/// access.
/// </remarks>
public IntPtr Handle {
get {
return _obj;
}
}
/// <summary>
/// EventList Property
/// </summary>
///
/// <remarks>
/// A list object containing all the events for this
/// object indexed by the Gtk+ signal name.
/// </remarks>
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;
}
}
/// <summary>
/// GetHashCode Method
/// </summary>
///
/// <remarks>
/// Calculates a hashing value.
/// </remarks>
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 ();
}
/// <summary>
/// Data property
/// </summary>
///
/// <remarks>
/// Stores and Accesses arbitrary data on the Object.
/// </remarks>
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);
/// <summary>
/// GetProperty Method
/// </summary>
///
/// <remarks>
/// Accesses a Value Property.
/// </remarks>
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);
/// <summary>
/// SetProperty Method
/// </summary>
///
/// <remarks>
/// Accesses a Value Property.
/// </remarks>
public void SetProperty (String name, GLib.Value val)
protected void SetProperty (String name, GLib.Value val)
{
g_object_set_property (Raw, name, val.Handle);
}

View file

@ -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");
}
}
}