Simplified Signal handling

* gdk/Display.custom: rework signal connection
* gdk/Window.custom: rework signal connection
* generator/Signal.cs: generate for new API.
* glib/Object.cs: add (Add|Remove)SignalHandler methods and use
them for the Notify connections.  Move to generic collections for
everything but the Data hash.
* glib/Signal.cs: kill Lookup methods and add delegate fields
* glib/ToggleRef.cs: remove Signals hash, it doesn't belong here.
* gtk/Clipboard.custom: rework signal connection
* gtk/ListStore.custom: rework signal connection
* gtk/TextView.custom: remove obsolete signal
* gtk/TreeModelAdapter.custom: rework signal connection
* gtk/TreeModelFilter.custom: rework signal connection
* gtk/TreeModelSort.custom: rework signal connection
* gtk/TreeStore.custom: rework signal connection
* gtk/Widget.custom: rework signal connection
* gtk/Window.custom: remove obsolete signal
This commit is contained in:
Mike Kestner 2011-03-24 18:11:10 -05:00
parent db738c401b
commit 6be0718ff2
15 changed files with 129 additions and 374 deletions

View file

@ -79,9 +79,9 @@
public void AddClientMessageFilter (Gdk.Atom message_type, Gdk.FilterFunc func) public void AddClientMessageFilter (Gdk.Atom message_type, Gdk.FilterFunc func)
{ {
GdkSharp.FilterFuncWrapper func_wrapper = new GdkSharp.FilterFuncWrapper (func); GdkSharp.FilterFuncWrapper func_wrapper = new GdkSharp.FilterFuncWrapper (func);
if (!PersistentData.Contains ("client_message_filter_func_list")) if (!Data.Contains ("client_message_filter_func_list"))
PersistentData ["client_message_filter_func_list"] = new ArrayList (); Data ["client_message_filter_func_list"] = new ArrayList ();
ArrayList func_list = PersistentData ["client_message_filter_func_list"] as ArrayList; ArrayList func_list = Data ["client_message_filter_func_list"] as ArrayList;
func_list.Add (func_wrapper); func_list.Add (func_wrapper);
gdk_display_add_client_message_filter (Handle, message_type == null ? IntPtr.Zero : message_type.Handle, func_wrapper.NativeDelegate, IntPtr.Zero); gdk_display_add_client_message_filter (Handle, message_type == null ? IntPtr.Zero : message_type.Handle, func_wrapper.NativeDelegate, IntPtr.Zero);
} }

View file

@ -130,9 +130,9 @@
public void AddFilter (FilterFunc function) public void AddFilter (FilterFunc function)
{ {
if (!PersistentData.Contains ("filter_func_hash")) if (!Data.Contains ("filter_func_hash"))
PersistentData ["filter_func_hash"] = new Hashtable (); Data ["filter_func_hash"] = new Hashtable ();
Hashtable hash = PersistentData ["filter_func_hash"] as Hashtable; Hashtable hash = Data ["filter_func_hash"] as Hashtable;
GdkSharp.FilterFuncWrapper wrapper = new GdkSharp.FilterFuncWrapper (function); GdkSharp.FilterFuncWrapper wrapper = new GdkSharp.FilterFuncWrapper (function);
hash [function] = wrapper; hash [function] = wrapper;
gdk_window_add_filter (Handle, wrapper.NativeDelegate, IntPtr.Zero); gdk_window_add_filter (Handle, wrapper.NativeDelegate, IntPtr.Zero);
@ -140,7 +140,7 @@
public void RemoveFilter (FilterFunc function) public void RemoveFilter (FilterFunc function)
{ {
Hashtable hash = PersistentData ["filter_func_hash"] as Hashtable; Hashtable hash = Data ["filter_func_hash"] as Hashtable;
GdkSharp.FilterFuncWrapper wrapper = hash [function] as GdkSharp.FilterFuncWrapper; GdkSharp.FilterFuncWrapper wrapper = hash [function] as GdkSharp.FilterFuncWrapper;
if (wrapper == null) if (wrapper == null)
return; return;

View file

@ -305,12 +305,10 @@ namespace GtkSharp.Generation {
sw.Write("new "); sw.Write("new ");
sw.WriteLine("event " + EventHandlerQualifiedName + " " + Name + " {"); sw.WriteLine("event " + EventHandlerQualifiedName + " " + Name + " {");
sw.WriteLine("\t\t\tadd {"); sw.WriteLine("\t\t\tadd {");
sw.WriteLine("\t\t\t\tGLib.Signal sig = GLib.Signal.Lookup (" + target + ", " + CName + args_type + ");"); sw.WriteLine("\t\t\t\t{0}.AddSignalHandler ({1}, value{2});", target, CName, args_type);
sw.WriteLine("\t\t\t\tsig.AddDelegate (value);");
sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t\t}");
sw.WriteLine("\t\t\tremove {"); sw.WriteLine("\t\t\tremove {");
sw.WriteLine("\t\t\t\tGLib.Signal sig = GLib.Signal.Lookup (" + target + ", " + CName + args_type + ");"); sw.WriteLine("\t\t\t\t{0}.RemoveSignalHandler ({1}, value);", target, CName);
sw.WriteLine("\t\t\t\tsig.RemoveDelegate (value);");
sw.WriteLine("\t\t\t}"); sw.WriteLine("\t\t\t}");
sw.WriteLine("\t\t}"); sw.WriteLine("\t\t}");
sw.WriteLine(); sw.WriteLine();

View file

@ -23,7 +23,7 @@
namespace GLib { namespace GLib {
using System; using System;
using System.Collections; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -34,9 +34,8 @@ namespace GLib {
IntPtr handle; IntPtr handle;
ToggleRef tref; ToggleRef tref;
bool disposed = false; bool disposed = false;
Hashtable data; static Dictionary<IntPtr, ToggleRef> Objects = new Dictionary<IntPtr, ToggleRef>();
static Hashtable Objects = new Hashtable(); static List<ToggleRef> PendingDestroys = new List<ToggleRef> ();
static ArrayList PendingDestroys = new ArrayList ();
static bool idle_queued; static bool idle_queued;
~Object () ~Object ()
@ -59,10 +58,10 @@ namespace GLib {
static bool PerformQueuedUnrefs () static bool PerformQueuedUnrefs ()
{ {
object [] references; ToggleRef[] references;
lock (PendingDestroys){ lock (PendingDestroys){
references = new object [PendingDestroys.Count]; references = new ToggleRef [PendingDestroys.Count];
PendingDestroys.CopyTo (references, 0); PendingDestroys.CopyTo (references, 0);
PendingDestroys.Clear (); PendingDestroys.Clear ();
idle_queued = false; idle_queued = false;
@ -80,8 +79,9 @@ namespace GLib {
return; return;
disposed = true; disposed = true;
ToggleRef toggle_ref = Objects [Handle] as ToggleRef; ToggleRef toggle_ref;
Objects.Remove (Handle); if (Objects.TryGetValue (Handle, out toggle_ref))
Objects.Remove (Handle);
try { try {
if (toggle_ref != null) if (toggle_ref != null)
toggle_ref.Free (); toggle_ref.Free ();
@ -103,8 +103,8 @@ namespace GLib {
Object obj = null; Object obj = null;
if (Objects.Contains (o)) { ToggleRef toggle_ref;
ToggleRef toggle_ref = Objects [o] as ToggleRef; if (Objects.TryGetValue (o, out toggle_ref)) {
if (toggle_ref != null) if (toggle_ref != null)
obj = toggle_ref.Target; obj = toggle_ref.Target;
} }
@ -166,11 +166,11 @@ namespace GLib {
// Key: The pointer to the ParamSpec of the property // Key: The pointer to the ParamSpec of the property
// Value: The corresponding PropertyInfo object // Value: The corresponding PropertyInfo object
static Hashtable properties; static Dictionary<IntPtr, PropertyInfo> properties;
static Hashtable Properties { static Dictionary<IntPtr, PropertyInfo> Properties {
get { get {
if (properties == null) if (properties == null)
properties = new Hashtable (); properties = new Dictionary<IntPtr, PropertyInfo> ();
return properties; return properties;
} }
} }
@ -298,11 +298,11 @@ namespace GLib {
static void GetPropertyCallback (IntPtr handle, uint property_id, ref GLib.Value value, IntPtr param_spec) static void GetPropertyCallback (IntPtr handle, uint property_id, ref GLib.Value value, IntPtr param_spec)
{ {
if (!Properties.Contains (param_spec)) if (!Properties.ContainsKey (param_spec))
return; return;
GLib.Object obj = GLib.Object.GetObject (handle, false); GLib.Object obj = GLib.Object.GetObject (handle, false);
value.Val = (Properties [param_spec] as PropertyInfo).GetValue (obj, new object [0]); value.Val = Properties [param_spec].GetValue (obj, new object [0]);
} }
static GetPropertyDelegate get_property_handler; static GetPropertyDelegate get_property_handler;
@ -319,11 +319,11 @@ namespace GLib {
static void SetPropertyCallback(IntPtr handle, uint property_id, ref GLib.Value value, IntPtr param_spec) static void SetPropertyCallback(IntPtr handle, uint property_id, ref GLib.Value value, IntPtr param_spec)
{ {
if (!Properties.Contains (param_spec)) if (!Properties.ContainsKey (param_spec))
return; return;
GLib.Object obj = GLib.Object.GetObject (handle, false); GLib.Object obj = GLib.Object.GetObject (handle, false);
(Properties [param_spec] as PropertyInfo).SetValue (obj, value.Val, new object [0]); Properties [param_spec].SetValue (obj, value.Val, new object [0]);
} }
static SetPropertyDelegate set_property_handler; static SetPropertyDelegate set_property_handler;
@ -456,131 +456,47 @@ namespace GLib {
} }
public static GLib.GType GType { public static GLib.GType GType {
get { get { return GType.Object; }
return GType.Object;
}
} }
protected string TypeName { protected string TypeName {
get { get { return NativeType.ToString (); }
return NativeType.ToString ();
}
} }
internal GLib.GType NativeType { internal GLib.GType NativeType {
get { get { return LookupGType (); }
return LookupGType ();
}
} }
internal ToggleRef ToggleRef { internal ToggleRef ToggleRef {
get { get { return tref; }
return tref;
}
} }
public IntPtr Handle { public IntPtr Handle {
get { get { return handle; }
return handle;
}
} }
public IntPtr OwnedHandle { public IntPtr OwnedHandle {
get { get { return g_object_ref (handle); }
return g_object_ref (handle);
}
}
Hashtable before_signals;
[Obsolete ("Replaced by GLib.Signal marshaling mechanism.")]
protected internal Hashtable BeforeSignals {
get {
if (before_signals == null)
before_signals = new Hashtable ();
return before_signals;
}
}
Hashtable after_signals;
[Obsolete ("Replaced by GLib.Signal marshaling mechanism.")]
protected internal Hashtable AfterSignals {
get {
if (after_signals == null)
after_signals = new Hashtable ();
return after_signals;
}
}
EventHandlerList before_handlers;
[Obsolete ("Replaced by GLib.Signal marshaling mechanism.")]
protected EventHandlerList BeforeHandlers {
get {
if (before_handlers == null)
before_handlers = new EventHandlerList ();
return before_handlers;
}
}
EventHandlerList after_handlers;
[Obsolete ("Replaced by GLib.Signal marshaling mechanism.")]
protected EventHandlerList AfterHandlers {
get {
if (after_handlers == null)
after_handlers = new EventHandlerList ();
return after_handlers;
}
}
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
delegate void NotifyDelegate (IntPtr handle, IntPtr pspec, IntPtr gch);
void NotifyCallback (IntPtr handle, IntPtr pspec, IntPtr gch)
{
try {
GLib.Signal sig = ((GCHandle) gch).Target as GLib.Signal;
if (sig == null)
throw new Exception("Unknown signal GC handle received " + gch);
NotifyArgs args = new NotifyArgs ();
args.Args = new object[1];
args.Args[0] = pspec;
NotifyHandler handler = (NotifyHandler) sig.Handler;
handler (GLib.Object.GetObject (handle), args);
} catch (Exception e) {
ExceptionManager.RaiseUnhandledException (e, false);
}
}
void ConnectNotification (string signal, NotifyHandler handler)
{
Signal sig = Signal.Lookup (this, signal, new NotifyDelegate (NotifyCallback));
sig.AddDelegate (handler);
} }
public void AddNotification (string property, NotifyHandler handler) public void AddNotification (string property, NotifyHandler handler)
{ {
ConnectNotification ("notify::" + property, handler); AddSignalHandler ("notify::" + property, handler, typeof(NotifyArgs));
} }
public void AddNotification (NotifyHandler handler) public void AddNotification (NotifyHandler handler)
{ {
ConnectNotification ("notify", handler); AddSignalHandler ("notify", handler, typeof(NotifyArgs));
}
void DisconnectNotification (string signal, NotifyHandler handler)
{
Signal sig = Signal.Lookup (this, signal, new NotifyDelegate (NotifyCallback));
sig.RemoveDelegate (handler);
} }
public void RemoveNotification (string property, NotifyHandler handler) public void RemoveNotification (string property, NotifyHandler handler)
{ {
DisconnectNotification ("notify::" + property, handler); RemoveSignalHandler ("notify::" + property, handler);
} }
public void RemoveNotification (NotifyHandler handler) public void RemoveNotification (NotifyHandler handler)
{ {
DisconnectNotification ("notify", handler); RemoveSignalHandler ("notify", handler);
} }
public override int GetHashCode () public override int GetHashCode ()
@ -588,25 +504,16 @@ namespace GLib {
return Handle.GetHashCode (); return Handle.GetHashCode ();
} }
public Hashtable Data { System.Collections.Hashtable data;
public System.Collections.Hashtable Data {
get { get {
if (data == null) if (data == null)
data = new Hashtable (); data = new System.Collections.Hashtable ();
return data; return data;
} }
} }
Hashtable persistent_data;
protected Hashtable PersistentData {
get {
if (persistent_data == null)
persistent_data = new Hashtable ();
return persistent_data;
}
}
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_object_get_property (IntPtr obj, IntPtr name, ref GLib.Value val); static extern void g_object_get_property (IntPtr obj, IntPtr name, ref GLib.Value val);
@ -639,6 +546,52 @@ namespace GLib {
GLib.Marshaller.Free (native_name); GLib.Marshaller.Free (native_name);
} }
Dictionary<string, Signal> signals;
Dictionary<string, Signal> Signals {
get {
if (signals == null)
signals = new Dictionary<string, Signal> ();
return signals;
}
}
public void AddSignalHandler (string name, Delegate handler)
{
AddSignalHandler (name, handler, typeof (EventArgs));
}
public void AddSignalHandler (string name, Delegate handler, Delegate marshaler)
{
Signal sig;
if (!Signals.TryGetValue (name, out sig)) {
sig = new Signal (this, name, marshaler);
Signals [name] = sig;
}
sig.AddDelegate (handler);
}
public void AddSignalHandler (string name, Delegate handler, Type args_type)
{
if (args_type == null)
args_type = handler.Method.GetParameters ()[1].ParameterType;
Signal sig;
if (!Signals.TryGetValue (name, out sig)) {
sig = new Signal (this, name, args_type);
Signals [name] = sig;
}
sig.AddDelegate (handler);
}
public void RemoveSignalHandler (string name, Delegate handler)
{
Signal sig;
if (Signals.TryGetValue (name, out sig))
sig.RemoveDelegate (handler);
}
protected static void OverrideVirtualMethod (GType gtype, string name, Delegate cb) protected static void OverrideVirtualMethod (GType gtype, string name, Delegate cb)
{ {
Signal.OverrideDefaultHandler (gtype, name, cb); Signal.OverrideDefaultHandler (gtype, name, cb);

View file

@ -133,27 +133,27 @@ namespace GLib {
} }
} }
ToggleRef tref; GLib.Object obj;
string name; string name;
Type args_type; Type args_type;
SignalClosure before_closure; SignalClosure before_closure;
SignalClosure after_closure; SignalClosure after_closure;
Delegate after_handler;
Delegate before_handler;
Delegate marshaler; Delegate marshaler;
private Signal (GLib.Object obj, string signal_name, Delegate marshaler) internal Signal (GLib.Object obj, string name, Delegate marshaler)
{ {
tref = obj.ToggleRef; this.obj = obj;
name = signal_name; this.name = name;
tref.Signals [name] = this;
this.marshaler = marshaler; this.marshaler = marshaler;
} }
private Signal (GLib.Object obj, string signal_name, Type args_type) internal Signal (GLib.Object obj, string name, Type args_type)
{ {
tref = obj.ToggleRef; this.obj = obj;
name = signal_name; this.name = name;
this.args_type = args_type; this.args_type = args_type;
tref.Signals [name] = this;
} }
internal void Free () internal void Free ()
@ -170,19 +170,14 @@ namespace GLib {
if (o == before_closure) { if (o == before_closure) {
before_closure.Disposed -= new EventHandler (ClosureDisposedHandler); before_closure.Disposed -= new EventHandler (ClosureDisposedHandler);
before_closure.Invoked -= new ClosureInvokedHandler (ClosureInvokedCB); before_closure.Invoked -= new ClosureInvokedHandler (ClosureInvokedCB);
if (tref.Target != null)
tref.Target.BeforeSignals.Remove (name);
before_closure = null; before_closure = null;
before_handler = null;
} else if (o == after_closure) { } else if (o == after_closure) {
after_closure.Disposed -= new EventHandler (ClosureDisposedHandler); after_closure.Disposed -= new EventHandler (ClosureDisposedHandler);
after_closure.Invoked -= new ClosureInvokedHandler (ClosureInvokedCB); after_closure.Invoked -= new ClosureInvokedHandler (ClosureInvokedCB);
if (tref.Target != null)
tref.Target.AfterSignals.Remove (name);
after_closure = null; after_closure = null;
after_handler = null;
} }
if (before_closure == null && after_closure == null)
tref.Signals.Remove (name);
} }
EventHandler closure_disposed_cb; EventHandler closure_disposed_cb;
@ -198,9 +193,9 @@ namespace GLib {
{ {
Delegate handler; Delegate handler;
if (o == before_closure) if (o == before_closure)
handler = args.Target.BeforeSignals [name] as Delegate; handler = before_handler;
else else
handler = args.Target.AfterSignals [name] as Delegate; handler = after_handler;
if (handler != null) if (handler != null)
handler.DynamicInvoke (new object[] {args.Target, args.Args}); handler.DynamicInvoke (new object[] {args.Target, args.Args});
@ -215,35 +210,13 @@ namespace GLib {
} }
} }
public static Signal Lookup (GLib.Object obj, string name)
{
return Lookup (obj, name, typeof (EventArgs));
}
public static Signal Lookup (GLib.Object obj, string name, Delegate marshaler)
{
Signal result = obj.ToggleRef.Signals [name];
if (result == null)
result = new Signal (obj, name, marshaler);
return result;
}
public static Signal Lookup (GLib.Object obj, string name, Type args_type)
{
Signal result = obj.ToggleRef.Signals [name];
if (result == null)
result = new Signal (obj, name, args_type);
return result;
}
public Delegate Handler { public Delegate Handler {
get { get {
InvocationHint hint = (InvocationHint) Marshal.PtrToStructure (g_signal_get_invocation_hint (tref.Handle), typeof (InvocationHint)); InvocationHint hint = (InvocationHint) Marshal.PtrToStructure (g_signal_get_invocation_hint (obj.Handle), typeof (InvocationHint));
if (hint.run_type == Flags.RunFirst) if (hint.run_type == Flags.RunFirst)
return tref.Target.BeforeSignals [name] as Delegate; return before_handler;
else else
return tref.Target.AfterSignals [name] as Delegate; return after_handler;
} }
} }
@ -253,23 +226,23 @@ namespace GLib {
args_type = d.Method.GetParameters ()[1].ParameterType; args_type = d.Method.GetParameters ()[1].ParameterType;
if (d.Method.IsDefined (typeof (ConnectBeforeAttribute), false)) { if (d.Method.IsDefined (typeof (ConnectBeforeAttribute), false)) {
tref.Target.BeforeSignals [name] = Delegate.Combine (tref.Target.BeforeSignals [name] as Delegate, d); before_handler = Delegate.Combine (before_handler, d);
if (before_closure == null) { if (before_closure == null) {
if (marshaler == null) if (marshaler == null)
before_closure = new SignalClosure (tref.Handle, name, args_type); before_closure = new SignalClosure (obj.Handle, name, args_type);
else else
before_closure = new SignalClosure (tref.Handle, name, marshaler, this); before_closure = new SignalClosure (obj.Handle, name, marshaler, this);
before_closure.Disposed += ClosureDisposedHandler; before_closure.Disposed += ClosureDisposedHandler;
before_closure.Invoked += ClosureInvokedHandler; before_closure.Invoked += ClosureInvokedHandler;
before_closure.Connect (false); before_closure.Connect (false);
} }
} else { } else {
tref.Target.AfterSignals [name] = Delegate.Combine (tref.Target.AfterSignals [name] as Delegate, d); after_handler = Delegate.Combine (after_handler, d);
if (after_closure == null) { if (after_closure == null) {
if (marshaler == null) if (marshaler == null)
after_closure = new SignalClosure (tref.Handle, name, args_type); after_closure = new SignalClosure (obj.Handle, name, args_type);
else else
after_closure = new SignalClosure (tref.Handle, name, marshaler, this); after_closure = new SignalClosure (obj.Handle, name, marshaler, this);
after_closure.Disposed += ClosureDisposedHandler; after_closure.Disposed += ClosureDisposedHandler;
after_closure.Invoked += ClosureInvokedHandler; after_closure.Invoked += ClosureInvokedHandler;
after_closure.Connect (true); after_closure.Connect (true);
@ -279,18 +252,15 @@ namespace GLib {
public void RemoveDelegate (Delegate d) public void RemoveDelegate (Delegate d)
{ {
if (tref.Target == null)
return;
if (d.Method.IsDefined (typeof (ConnectBeforeAttribute), false)) { if (d.Method.IsDefined (typeof (ConnectBeforeAttribute), false)) {
tref.Target.BeforeSignals [name] = Delegate.Remove (tref.Target.BeforeSignals [name] as Delegate, d); before_handler = Delegate.Remove (before_handler, d);
if (tref.Target.BeforeSignals [name] == null && before_closure != null) { if (before_handler == null && before_closure != null) {
before_closure.Dispose (); before_closure.Dispose ();
before_closure = null; before_closure = null;
} }
} else { } else {
tref.Target.AfterSignals [name] = Delegate.Remove (tref.Target.AfterSignals [name] as Delegate, d); after_handler = Delegate.Remove (after_handler, d);
if (tref.Target.AfterSignals [name] == null && after_closure != null) { if (after_handler == null && after_closure != null) {
after_closure.Dispose (); after_closure.Dispose ();
after_closure = null; after_closure = null;
} }

View file

@ -31,7 +31,6 @@ namespace GLib {
IntPtr handle; IntPtr handle;
object reference; object reference;
GCHandle gch; GCHandle gch;
Dictionary<string, Signal> signals;
public ToggleRef (GLib.Object target) public ToggleRef (GLib.Object target)
{ {
@ -46,14 +45,6 @@ namespace GLib {
get { return handle; } get { return handle; }
} }
public Dictionary<string, Signal> Signals {
get {
if (signals == null)
signals = new Dictionary<string, Signal> ();
return signals;
}
}
public GLib.Object Target { public GLib.Object Target {
get { get {
if (reference == null) if (reference == null)
@ -68,10 +59,6 @@ namespace GLib {
public void Free () public void Free ()
{ {
Signal[] signals = new Signal [Signals.Count];
Signals.Values.CopyTo (signals, 0);
foreach (Signal s in signals)
s.Free ();
if (hardened) if (hardened)
g_object_unref (handle); g_object_unref (handle);
else else

View file

@ -27,8 +27,8 @@
void ClearProxy (Clipboard clipboard) void ClearProxy (Clipboard clipboard)
{ {
if (PersistentData ["clear_func"] != null) { if (Data ["clear_func"] != null) {
ClipboardClearFunc clear = PersistentData ["clear_func"] as ClipboardClearFunc; ClipboardClearFunc clear = Data ["clear_func"] as ClipboardClearFunc;
clear (clipboard); clear (clipboard);
} }
SetPersistentData (null, null, null); SetPersistentData (null, null, null);
@ -36,9 +36,9 @@
void SetPersistentData (object get_func_wrapper, object clear_func, object clear_proxy_wrapper) void SetPersistentData (object get_func_wrapper, object clear_func, object clear_proxy_wrapper)
{ {
PersistentData ["get_func_wrapper"] = get_func_wrapper; Data ["get_func_wrapper"] = get_func_wrapper;
PersistentData ["clear_func"] = clear_func; Data ["clear_func"] = clear_func;
PersistentData ["clear_proxy_wrapper"] = clear_proxy_wrapper; Data ["clear_proxy_wrapper"] = clear_proxy_wrapper;
} }
public bool SetWithData (TargetEntry[] targets, ClipboardGetFunc get_func, ClipboardClearFunc clear_func) public bool SetWithData (TargetEntry[] targets, ClipboardGetFunc get_func, ClipboardClearFunc clear_func)

View file

@ -281,12 +281,10 @@
[GLib.Signal("rows_reordered")] [GLib.Signal("rows_reordered")]
public event Gtk.RowsReorderedHandler RowsReordered { public event Gtk.RowsReorderedHandler RowsReordered {
add { add {
GLib.Signal sig = GLib.Signal.Lookup (this, "rows_reordered", new RowsReorderedSignalDelegate(RowsReorderedSignalCallback)); AddSignalHandler ("rows_reordered", value, new RowsReorderedSignalDelegate(RowsReorderedSignalCallback));
sig.AddDelegate (value);
} }
remove { remove {
GLib.Signal sig = GLib.Signal.Lookup (this, "rows_reordered", new RowsReorderedSignalDelegate(RowsReorderedSignalCallback)); RemoveSignalHandler ("rows_reordered", value);
sig.RemoveDelegate (value);
} }
} }

View file

@ -35,74 +35,3 @@
Raw = gtk_text_view_new_with_buffer (buffer.Handle); Raw = gtk_text_view_new_with_buffer (buffer.Handle);
} }
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
delegate void MoveFocusSignalDelegate (IntPtr arg0, int arg1, IntPtr gch);
static void MoveFocusSignalCallback (IntPtr arg0, int arg1, IntPtr gch)
{
Gtk.MoveFocusArgs args = new Gtk.MoveFocusArgs ();
try {
GLib.Signal sig = ((GCHandle) gch).Target as GLib.Signal;
if (sig == null)
throw new Exception("Unknown signal GC handle received " + gch);
args.Args = new object[1];
args.Args[0] = (Gtk.DirectionType) arg1;
Gtk.MoveFocusHandler handler = (Gtk.MoveFocusHandler) sig.Handler;
handler (GLib.Object.GetObject (arg0), args);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
delegate void MoveFocusVMDelegate (IntPtr text_view, int direction);
static MoveFocusVMDelegate MoveFocusVMCallback;
static void movefocus_cb (IntPtr text_view, int direction)
{
try {
TextView text_view_managed = GLib.Object.GetObject (text_view, false) as TextView;
text_view_managed.OnMoveFocus ((Gtk.DirectionType) direction);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
private static void OverrideMoveFocus (GLib.GType gtype)
{
if (MoveFocusVMCallback == null)
MoveFocusVMCallback = new MoveFocusVMDelegate (movefocus_cb);
OverrideVirtualMethod (gtype, "move_focus", MoveFocusVMCallback);
}
[Obsolete ("Replaced by keybinding signal on Gtk.Widget")]
[GLib.DefaultSignalHandler(Type=typeof(Gtk.TextView), ConnectionMethod="OverrideMoveFocus")]
protected virtual void OnMoveFocus (Gtk.DirectionType direction)
{
GLib.Value ret = GLib.Value.Empty;
GLib.ValueArray inst_and_params = new GLib.ValueArray (2);
GLib.Value[] vals = new GLib.Value [2];
vals [0] = new GLib.Value (this);
inst_and_params.Append (vals [0]);
vals [1] = new GLib.Value (direction);
inst_and_params.Append (vals [1]);
g_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);
foreach (GLib.Value v in vals)
v.Dispose ();
}
[Obsolete ("Replaced by keybinding signal on Gtk.Widget")]
[GLib.Signal("move_focus")]
public event Gtk.MoveFocusHandler MoveFocus {
add {
GLib.Signal sig = GLib.Signal.Lookup (this, "move_focus", new MoveFocusSignalDelegate(MoveFocusSignalCallback));
sig.AddDelegate (value);
}
remove {
GLib.Signal sig = GLib.Signal.Lookup (this, "move_focus", new MoveFocusSignalDelegate(MoveFocusSignalCallback));
sig.RemoveDelegate (value);
}
}

View file

@ -170,12 +170,10 @@
[GLib.Signal("rows_reordered")] [GLib.Signal("rows_reordered")]
public event Gtk.RowsReorderedHandler RowsReordered { public event Gtk.RowsReorderedHandler RowsReordered {
add { add {
GLib.Signal sig = GLib.Signal.Lookup (GLib.Object.GetObject (Handle), "rows_reordered", new RowsReorderedSignalDelegate(RowsReorderedSignalCallback)); GLib.Object.GetObject (Handle).AddSignalHandler ("rows_reordered", value, new RowsReorderedSignalDelegate(RowsReorderedSignalCallback));
sig.AddDelegate (value);
} }
remove { remove {
GLib.Signal sig = GLib.Signal.Lookup (GLib.Object.GetObject (Handle), "rows_reordered", new RowsReorderedSignalDelegate(RowsReorderedSignalCallback)); GLib.Object.GetObject (Handle).RemoveSignalHandler ("rows_reordered", value);
sig.RemoveDelegate (value);
} }
} }

View file

@ -172,12 +172,10 @@
[GLib.Signal("rows_reordered")] [GLib.Signal("rows_reordered")]
public event Gtk.RowsReorderedHandler RowsReordered { public event Gtk.RowsReorderedHandler RowsReordered {
add { add {
GLib.Signal sig = GLib.Signal.Lookup (this, "rows_reordered", new RowsReorderedSignalDelegate(RowsReorderedSignalCallback)); AddSignalHandler ("rows_reordered", value, new RowsReorderedSignalDelegate(RowsReorderedSignalCallback));
sig.AddDelegate (value);
} }
remove { remove {
GLib.Signal sig = GLib.Signal.Lookup (this, "rows_reordered", new RowsReorderedSignalDelegate(RowsReorderedSignalCallback)); RemoveSignalHandler ("rows_reordered", value);
sig.RemoveDelegate (value);
} }
} }

View file

@ -175,12 +175,10 @@
[GLib.Signal("rows_reordered")] [GLib.Signal("rows_reordered")]
public event Gtk.RowsReorderedHandler RowsReordered { public event Gtk.RowsReorderedHandler RowsReordered {
add { add {
GLib.Signal sig = GLib.Signal.Lookup (this, "rows_reordered", new RowsReorderedSignalDelegate(RowsReorderedSignalCallback)); AddSignalHandler ("rows_reordered", value, new RowsReorderedSignalDelegate(RowsReorderedSignalCallback));
sig.AddDelegate (value);
} }
remove { remove {
GLib.Signal sig = GLib.Signal.Lookup (this, "rows_reordered", new RowsReorderedSignalDelegate(RowsReorderedSignalCallback)); RemoveSignalHandler ("rows_reordered", value);
sig.RemoveDelegate (value);
} }
} }

View file

@ -397,12 +397,11 @@
[GLib.Signal("rows_reordered")] [GLib.Signal("rows_reordered")]
public event Gtk.RowsReorderedHandler RowsReordered { public event Gtk.RowsReorderedHandler RowsReordered {
add { add {
GLib.Signal sig = GLib.Signal.Lookup (this, "rows_reordered", new RowsReorderedSignalDelegate(RowsReorderedSignalCallback)); AddSignalHandler ("rows_reordered", value, new RowsReorderedSignalDelegate(RowsReorderedSignalCallback));
sig.AddDelegate (value);
} }
remove { remove {
GLib.Signal sig = GLib.Signal.Lookup (this, "rows_reordered", new RowsReorderedSignalDelegate(RowsReorderedSignalCallback)); RemoveSignalHandler ("rows_reordered", value);
sig.RemoveDelegate (value);
} }
} }

View file

@ -347,12 +347,10 @@ public void Path (out string path, out string path_reversed)
event EventHandler InternalDestroyed { event EventHandler InternalDestroyed {
add { add {
GLib.Signal sig = GLib.Signal.Lookup (this, "destroy"); AddSignalHandler ("destroy", value);
sig.AddDelegate (value);
} }
remove { remove {
GLib.Signal sig = GLib.Signal.Lookup (this, "destroy"); RemoveSignalHandler ("destroy", value);
sig.RemoveDelegate (value);
} }
} }

View file

@ -86,74 +86,3 @@
} }
} }
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
delegate void MoveFocusSignalDelegate (IntPtr arg0, int arg1, IntPtr gch);
static void MoveFocusSignalCallback (IntPtr arg0, int arg1, IntPtr gch)
{
Gtk.MoveFocusArgs args = new Gtk.MoveFocusArgs ();
try {
GLib.Signal sig = ((GCHandle) gch).Target as GLib.Signal;
if (sig == null)
throw new Exception("Unknown signal GC handle received " + gch);
args.Args = new object[1];
args.Args[0] = (Gtk.DirectionType) arg1;
Gtk.MoveFocusHandler handler = (Gtk.MoveFocusHandler) sig.Handler;
handler (GLib.Object.GetObject (arg0), args);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
delegate void MoveFocusVMDelegate (IntPtr window, int direction);
static MoveFocusVMDelegate MoveFocusVMCallback;
static void movefocus_cb (IntPtr window, int direction)
{
try {
Window window_managed = GLib.Object.GetObject (window, false) as Window;
window_managed.OnMoveFocus ((Gtk.DirectionType) direction);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
private static void OverrideMoveFocus (GLib.GType gtype)
{
if (MoveFocusVMCallback == null)
MoveFocusVMCallback = new MoveFocusVMDelegate (movefocus_cb);
OverrideVirtualMethod (gtype, "move_focus", MoveFocusVMCallback);
}
[Obsolete ("Replaced by Keybinding signal on Gtk.Widget")]
[GLib.DefaultSignalHandler(Type=typeof(Gtk.Window), ConnectionMethod="OverrideMoveFocus")]
protected virtual void OnMoveFocus (Gtk.DirectionType direction)
{
GLib.Value ret = GLib.Value.Empty;
GLib.ValueArray inst_and_params = new GLib.ValueArray (2);
GLib.Value[] vals = new GLib.Value [2];
vals [0] = new GLib.Value (this);
inst_and_params.Append (vals [0]);
vals [1] = new GLib.Value (direction);
inst_and_params.Append (vals [1]);
g_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);
foreach (GLib.Value v in vals)
v.Dispose ();
}
[Obsolete ("Replaced by Keybinding signal on Gtk.Widget")]
[GLib.Signal("move_focus")]
public event Gtk.MoveFocusHandler MoveFocus {
add {
GLib.Signal sig = GLib.Signal.Lookup (this, "move_focus", new MoveFocusSignalDelegate(MoveFocusSignalCallback));
sig.AddDelegate (value);
}
remove {
GLib.Signal sig = GLib.Signal.Lookup (this, "move_focus", new MoveFocusSignalDelegate(MoveFocusSignalCallback));
sig.RemoveDelegate (value);
}
}