static void OnMarshal(IntPtr closure, ref GLib.Value retval, uint argc, IntPtr argsPtr, IntPtr ihint, IntPtr data) { object [] args = new object[argc - 1]; object o = ((GLib.Value)Marshal.PtrToStructure(argsPtr, typeof(GLib.Value))).Val; for (int i = 1; i < argc; i++) { IntPtr struct_ptr = (IntPtr)((long)argsPtr + (i * gvalue_struct_size)); GLib.Value argument = (GLib.Value)Marshal.PtrToStructure(struct_ptr, typeof(GLib.Value)); args[i - 1] = argument.Val; } if (data == IntPtr.Zero) { Console.Error.WriteLine("No available data"); return; } ObjectSignalKey k = (ObjectSignalKey)((GCHandle)data).Target; if (k != null) { SignalInfo si = (SignalInfo)SignalHandlers[k]; GLib.SignalArgs arg = (GLib.SignalArgs)Activator.CreateInstance(si.ArgsType); arg.Args = args; si.RegisteredHandler.DynamicInvoke(new object[] { o, arg }); if (arg.RetVal != null) { retval.Val = arg.RetVal; } } }
public static void Connect(GLib.Object o, string name, bool after, Delegate handler) { Delegate newHandler; ObjectSignalKey k = new ObjectSignalKey (o, name); if (!SignalInfo.IsValidDelegate (handler)) throw new Exception ("Invalid delegate"); if (SignalHandlers[k] != null) { SignalInfo si = (SignalInfo) SignalHandlers[k]; if (!si.IsCompatibleDelegate (handler)) throw new Exception ("Incompatible delegate"); newHandler = Delegate.Combine (si.RegisteredHandler, handler); si.UpdateArgsType (handler); si.RegisteredHandler = newHandler; } else { if (!SignalInfo.IsValidDelegate (handler)) throw new Exception ("Invalid delegate"); IntPtr closure = g_closure_new_simple (g_closure_sizeof, IntPtr.Zero); g_closure_set_meta_marshal (closure, (IntPtr) GCHandle.Alloc (k), marshalHandler); uint signalId = g_signal_connect_closure (o.Handle, name, closure, after); SignalHandlers.Add (k, new SignalInfo (signalId, closure, handler)); } }
public override bool Equals(object o) { if (o is ObjectSignalKey) { ObjectSignalKey k = (ObjectSignalKey)o; return(k.o.Equals(this.o) && signal_name.Equals(k.signal_name)); } return(base.Equals(o)); }
public static void Disconnect(GLib.Object o, string name, Delegate handler) { ObjectSignalKey k = new ObjectSignalKey(o, name); if (SignalHandlers[k] != null) { SignalInfo si = (SignalInfo)SignalHandlers[k]; Delegate newHandler = Delegate.Remove(si.RegisteredHandler, handler); if (newHandler == null || handler == null) { g_signal_handler_disconnect(o.Handle, si.HandlerId); SignalHandlers.Remove(k); } else { si.RegisteredHandler = newHandler; } } }
public static void Connect(GLib.Object o, string name, bool after, Delegate handler) { Delegate newHandler; ObjectSignalKey k = new ObjectSignalKey(o, name); if (!SignalInfo.IsValidDelegate(handler)) { throw new Exception("Invalid delegate"); } if (SignalHandlers [k] != null) { SignalInfo si = (SignalInfo)SignalHandlers [k]; if (!si.IsCompatibleDelegate(handler)) { throw new Exception("Incompatible delegate"); } newHandler = Delegate.Combine(si.RegisteredHandler, handler); si.UpdateArgsType(handler); si.RegisteredHandler = newHandler; } else { if (!SignalInfo.IsValidDelegate(handler)) { throw new Exception("Invalid delegate"); } // Let's allocate 64bytes for the GClosure, it should be more than necessary. IntPtr closure = g_closure_new_simple(64, IntPtr.Zero); GCHandle gch = GCHandle.Alloc(k); g_closure_set_meta_marshal(closure, (IntPtr)gch, marshalHandler); uint signalId = g_signal_connect_closure(o.Handle, name, closure, after); SignalHandlers.Add(k, new SignalInfo(signalId, closure, handler, gch)); } }
public static void Disconnect(GLib.Object o, string name, Delegate handler) { ObjectSignalKey k = new ObjectSignalKey (o, name); if (SignalHandlers[k] != null) { SignalInfo si = (SignalInfo) SignalHandlers[k]; Delegate newHandler = Delegate.Remove (si.RegisteredHandler, handler); if (newHandler == null || handler == null) { g_signal_handler_disconnect (o.Handle, si.HandlerId); SignalHandlers.Remove (k); } else { si.RegisteredHandler = newHandler; } } }