* atk/Object.custom: Track API changes in GLib.Signal.

* glib/Signal.cs: AddEmissionHook binding (for closing #386950), and
  change API of Emit to mimic the detailed_signal pattern.
* glib/GType.cs: GType.FromName: new wrapper for native call.
* glib/ObjectManager.cs: Use the new FromName managed method.

svn path=/trunk/gtk-sharp/; revision=103198
This commit is contained in:
Andrés G. Aragoneses 2008-05-14 16:03:13 +00:00
parent d1dbdf0316
commit 52e68fbeb6
5 changed files with 63 additions and 9 deletions

View file

@ -1,3 +1,11 @@
2008-05-14 Andres G. Aragoneses <aaragoneses@novell.com>
* atk/Object.custom: Track API changes in GLib.Signal.
* glib/Signal.cs: AddEmissionHook binding (for closing #386950), and
change API of Emit to mimic the detailed_signal pattern.
* glib/GType.cs: GType.FromName: new wrapper for native call.
* glib/ObjectManager.cs: Use the new FromName managed method.
2008-05-08 Mike Kestner <mkestner@novell.com> 2008-05-08 Mike Kestner <mkestner@novell.com>
* atk/atk-api-2.12.raw: reparsed. * atk/atk-api-2.12.raw: reparsed.

View file

@ -94,7 +94,9 @@
protected void EmitChildrenChanged (ChildrenChangedDetail detail, uint child_index, Atk.Object child) protected void EmitChildrenChanged (ChildrenChangedDetail detail, uint child_index, Atk.Object child)
{ {
GLib.Signal.Emit (this, "children-changed", detail.ToString().ToLower(), child_index, child); GLib.Signal.Emit (this,
"children-changed::" + detail.ToString ().ToLower (),
child_index, child);
} }
protected enum ChildrenChangedDetail protected enum ChildrenChangedDetail

View file

@ -37,6 +37,11 @@ namespace GLib {
this.val = val; this.val = val;
} }
public static GType FromName (string native_name)
{
return new GType (g_type_from_name (native_name));
}
public static readonly GType Invalid = new GType ((IntPtr) TypeFundamentals.TypeInvalid); public static readonly GType Invalid = new GType ((IntPtr) TypeFundamentals.TypeInvalid);
public static readonly GType None = new GType ((IntPtr) TypeFundamentals.TypeNone); public static readonly GType None = new GType ((IntPtr) TypeFundamentals.TypeNone);
public static readonly GType Interface = new GType ((IntPtr) TypeFundamentals.TypeInterface); public static readonly GType Interface = new GType ((IntPtr) TypeFundamentals.TypeInterface);
@ -196,6 +201,9 @@ namespace GLib {
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_name (IntPtr raw); static extern IntPtr g_type_name (IntPtr raw);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_from_name (string name);
public override string ToString () public override string ToString ()
{ {
return Marshaller.Utf8PtrToString (g_type_name (val)); return Marshaller.Utf8PtrToString (g_type_name (val));

View file

@ -58,7 +58,7 @@ namespace GLib {
[Obsolete ("Replaced by GType.Register (GType, Type)")] [Obsolete ("Replaced by GType.Register (GType, Type)")]
public static void RegisterType (string native_name, string mangled) public static void RegisterType (string native_name, string mangled)
{ {
RegisterType (new GType (g_type_from_name (native_name)), Type.GetType (mangled)); RegisterType (GType.FromName (native_name), Type.GetType (mangled));
} }
[Obsolete ("Replaced by GType.Register (GType, Type)")] [Obsolete ("Replaced by GType.Register (GType, Type)")]
@ -86,8 +86,5 @@ namespace GLib {
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_parent (IntPtr typ); static extern IntPtr g_type_parent (IntPtr typ);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_type_from_name (string name);
} }
} }

View file

@ -1,8 +1,9 @@
// GLib.Signal.cs - signal marshaling class // GLib.Signal.cs - signal marshaling class
// //
// Authors: Mike Kestner <mkestner@novell.com> // Authors: Mike Kestner <mkestner@novell.com>
// Andrés G. Aragoneses <aaragoneses@novell.com>
// //
// Copyright (c) 2005 Novell, Inc. // Copyright (c) 2005,2008 Novell, Inc.
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General // modify it under the terms of version 2 of the Lesser GNU General
@ -278,10 +279,28 @@ namespace GLib {
} }
} }
public static object Emit (GLib.Object instance, string signal_name, string detail, params object[] args) // format: children-changed::add
private static void ParseSignalDetail (string signal_detail, out string signal_name, out uint gquark)
{ {
uint signal_id = GetSignalId (signal_name, instance); //can't use String.Split because it doesn't accept a string arg (only char) in the 1.x profile
uint gquark = GetGQuarkFromString (detail); int link_pos = signal_detail.IndexOf ("::");
if (link_pos < 0) {
gquark = 0;
signal_name = signal_detail;
} else if (link_pos == 0) {
throw new FormatException ("Invalid detailed_signal: " + signal_detail);
} else {
signal_name = signal_detail.Substring (0, link_pos);
gquark = GetGQuarkFromString (signal_detail.Substring (link_pos + 2));
}
}
public static object Emit (GLib.Object instance, string detailed_signal, params object[] args)
{
uint gquark, signal_id;
string signal_name;
ParseSignalDetail (detailed_signal, out signal_name, out gquark);
signal_id = GetSignalId (signal_name, instance);
GLib.Value[] vals = new GLib.Value [args.Length + 1]; GLib.Value[] vals = new GLib.Value [args.Length + 1];
GLib.ValueArray inst_and_params = new GLib.ValueArray ((uint) args.Length + 1); GLib.ValueArray inst_and_params = new GLib.ValueArray ((uint) args.Length + 1);
@ -314,12 +333,28 @@ namespace GLib {
private static uint GetSignalId (string signal_name, GLib.Object obj) private static uint GetSignalId (string signal_name, GLib.Object obj)
{ {
IntPtr typeid = gtksharp_get_type_id (obj.Handle); IntPtr typeid = gtksharp_get_type_id (obj.Handle);
return GetSignalId (signal_name, typeid);
}
private static uint GetSignalId (string signal_name, IntPtr typeid)
{
IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (signal_name); IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (signal_name);
uint signal_id = g_signal_lookup (native_name, typeid); uint signal_id = g_signal_lookup (native_name, typeid);
GLib.Marshaller.Free (native_name); GLib.Marshaller.Free (native_name);
return signal_id; return signal_id;
} }
public static ulong AddEmissionHook (string detailed_signal, GLib.GType type, EmissionHook handler_func)
{
uint gquark;
string signal_name;
ParseSignalDetail (detailed_signal, out signal_name, out gquark);
uint signal_id = GetSignalId (signal_name, type.Val);
if (signal_id == 0)
throw new Exception ("Invalid signal name: " + signal_name);
return g_signal_add_emission_hook (signal_id, gquark, new EmissionHookMarshaler (handler_func).Callback, IntPtr.Zero, IntPtr.Zero);
}
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_signal_get_invocation_hint (IntPtr instance); static extern IntPtr g_signal_get_invocation_hint (IntPtr instance);
@ -335,6 +370,10 @@ namespace GLib {
[DllImport("glibsharpglue-2")] [DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_get_type_id (IntPtr raw); static extern IntPtr gtksharp_get_type_id (IntPtr raw);
[DllImport("libgobject-2.0-0.dll")]
static extern ulong g_signal_add_emission_hook (uint signal_id, uint gquark_detail, EmissionHookNative hook_func, IntPtr hook_data, IntPtr data_destroy);
} }
} }