mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2025-01-11 09:25:30 +00:00
2003-12-30 Mike Kestner <mkestner@ximian.com>
* glib/Object.cs (ConnectDefaultHandlers): reflection code to hook up overridden default signal handlers. * glue/type.c (gtksharp_override_virtual_method): peek the gtype and ref the class if it isn't created yet. * sample/Subclass.cs : update to override Button.OnClicked. svn path=/trunk/gtk-sharp/; revision=21559
This commit is contained in:
parent
9f3cd6ae80
commit
6e3879ca4b
|
@ -1,3 +1,11 @@
|
|||
2003-12-30 Mike Kestner <mkestner@ximian.com>
|
||||
|
||||
* glib/Object.cs (ConnectDefaultHandlers): reflection code to
|
||||
hook up overridden default signal handlers.
|
||||
* glue/type.c (gtksharp_override_virtual_method): peek the gtype
|
||||
and ref the class if it isn't created yet.
|
||||
* sample/Subclass.cs : update to override Button.OnClicked.
|
||||
|
||||
2003-12-26 Mike Kestner <mkestner@ximian.com>
|
||||
|
||||
* glue/selectiondata.c : new glue to make SelectionData opaque
|
||||
|
|
|
@ -141,6 +141,28 @@ namespace GLib {
|
|||
return GetObject (o, false);
|
||||
}
|
||||
|
||||
private static void ConnectDefaultHandlers (GType gtype, System.Type t)
|
||||
{
|
||||
foreach (MethodInfo minfo in t.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) {
|
||||
MethodInfo baseinfo = minfo.GetBaseDefinition ();
|
||||
if (baseinfo == minfo)
|
||||
continue;
|
||||
|
||||
foreach (object attr in baseinfo.GetCustomAttributes (true)) {
|
||||
if (attr.ToString () != "GLib.DefaultSignalHandlerAttribute")
|
||||
continue;
|
||||
|
||||
DefaultSignalHandlerAttribute sigattr = attr as DefaultSignalHandlerAttribute;
|
||||
MethodInfo connector = sigattr.Type.GetMethod (sigattr.ConnectionMethod, BindingFlags.Static | BindingFlags.NonPublic);
|
||||
object[] parms = new object [1];
|
||||
parms [0] = gtype;
|
||||
connector.Invoke (null, parms);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[DllImport("gtksharpglue")]
|
||||
static extern IntPtr gtksharp_register_type (string name, IntPtr parent_type);
|
||||
|
||||
|
@ -165,7 +187,9 @@ namespace GLib {
|
|||
GType parent_gtype = (GType) pi.GetValue (null, null);
|
||||
string name = t.Namespace.Replace(".", "_") + t.Name;
|
||||
GtkSharp.ObjectManager.RegisterType (name, t.Namespace + t.Name, t.Assembly.GetName().Name);
|
||||
return new GLib.GType (gtksharp_register_type (name, parent_gtype.Val));
|
||||
GType gtype = new GType (gtksharp_register_type (name, parent_gtype.Val));
|
||||
ConnectDefaultHandlers (gtype, t);
|
||||
return gtype;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -71,6 +71,8 @@ gtksharp_register_type (gchar *name, GType parent)
|
|||
void
|
||||
gtksharp_override_virtual_method (GType g_type, const gchar *name, GCallback callback)
|
||||
{
|
||||
if (g_type_class_peek (g_type) == NULL)
|
||||
g_type_class_ref (g_type);
|
||||
guint id = g_signal_lookup (name, g_type);
|
||||
GClosure *closure = g_cclosure_new (callback, NULL, NULL);
|
||||
g_signal_override_class_closure (id, g_type, closure);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Subclass.cs - Widget subclass Test implementation
|
||||
// Subclass.cs - Widget subclass Test
|
||||
//
|
||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
// Author: Mike Kestner <mkestner@ximian.com>
|
||||
//
|
||||
// (c) 2001-2002 Mike Kestner
|
||||
// (c) 2001-2003 Mike Kestner, Novell, Inc.
|
||||
|
||||
namespace GtkSamples {
|
||||
|
||||
|
@ -17,35 +17,22 @@ namespace GtkSamples {
|
|||
{
|
||||
Application.Init ();
|
||||
Window win = new Window ("Button Tester");
|
||||
win.DefaultSize = new Size (200, 150);
|
||||
win.DeleteEvent += new DeleteEventHandler (Window_Delete);
|
||||
Button btn = new MyButton ();
|
||||
btn.Label = "I'm a subclassed button";
|
||||
btn.Clicked += new EventHandler (btn_click);
|
||||
win.Add (btn);
|
||||
win.ShowAll ();
|
||||
Application.Run ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void btn_click (object obj, EventArgs args)
|
||||
{
|
||||
Console.WriteLine ("Button Clicked");
|
||||
}
|
||||
|
||||
static void Window_Delete (object obj, DeleteEventArgs args)
|
||||
{
|
||||
Application.Quit ();
|
||||
args.RetVal = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class MyButton : Gtk.Button {
|
||||
|
||||
static GLib.GType gtype = GLib.GType.Invalid;
|
||||
|
||||
public MyButton () : base (GType) {}
|
||||
public MyButton () : base (GType)
|
||||
{
|
||||
Label = "I'm a subclassed button";
|
||||
}
|
||||
|
||||
public static new GLib.GType GType {
|
||||
get {
|
||||
|
@ -54,5 +41,10 @@ namespace GtkSamples {
|
|||
return gtype;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClicked ()
|
||||
{
|
||||
Console.WriteLine ("Button::Clicked default handler fired.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue