コード例 #1
0
ファイル: Signal.cs プロジェクト: shana/gtk-sharp
        void ClosureDisposedCB(object o, EventArgs args)
        {
            if (o == before_closure)
            {
                before_closure.Disposed -= new EventHandler(ClosureDisposedHandler);
                before_closure.Invoked  -= new ClosureInvokedHandler(ClosureInvokedCB);
                if (tref.Target != null)
                {
                    tref.Target.BeforeSignals.Remove(name);
                }
                before_closure = null;
            }
            else if (o == after_closure)
            {
                after_closure.Disposed -= new EventHandler(ClosureDisposedHandler);
                after_closure.Invoked  -= new ClosureInvokedHandler(ClosureInvokedCB);
                if (tref.Target != null)
                {
                    tref.Target.AfterSignals.Remove(name);
                }
                after_closure = null;
            }

            if (before_closure == null && after_closure == null)
            {
                tref.Signals.Remove(name);
            }
        }
コード例 #2
0
ファイル: Signal.cs プロジェクト: shana/gtk-sharp
        public void RemoveDelegate(Delegate d)
        {
            if (tref.Target == null)
            {
                return;
            }

            if (d.Method.IsDefined(typeof(ConnectBeforeAttribute), false))
            {
                tref.Target.BeforeSignals [name] = Delegate.Remove(tref.Target.BeforeSignals [name] as Delegate, d);
                if (tref.Target.BeforeSignals [name] == null && before_closure != null)
                {
                    before_closure.Dispose();
                    before_closure = null;
                }
            }
            else
            {
                tref.Target.AfterSignals [name] = Delegate.Remove(tref.Target.AfterSignals [name] as Delegate, d);
                if (tref.Target.AfterSignals [name] == null && after_closure != null)
                {
                    after_closure.Dispose();
                    after_closure = null;
                }
            }
        }
コード例 #3
0
ファイル: SignalClosure.cs プロジェクト: xclaesse/gtk-sharp
        static void NotifyCallback(IntPtr data, IntPtr raw_closure)
        {
            SignalClosure closure = closures [raw_closure] as SignalClosure;

            if (closure != null)
            {
                closure.Dispose();
            }
        }
コード例 #4
0
ファイル: SignalClosure.cs プロジェクト: xclaesse/gtk-sharp
        static void MarshalCallback(IntPtr raw_closure, IntPtr return_val, uint n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data)
        {
            string message = String.Empty;

            try {
                SignalClosure closure = closures [raw_closure] as SignalClosure;
                message = "Marshaling " + closure.name + " signal";
                Value       objval = (Value)Marshal.PtrToStructure(param_values, typeof(Value));
                GLib.Object __obj  = objval.Val as GLib.Object;
                if (__obj == null)
                {
                    return;
                }

                if (closure.args_type == typeof(EventArgs))
                {
                    closure.Invoke(new ClosureInvokedArgs(__obj, EventArgs.Empty));
                    return;
                }

                SignalArgs args = Activator.CreateInstance(closure.args_type, new object [0]) as SignalArgs;
                args.Args = new object [n_param_vals - 1];
                GLib.Value[] vals = new GLib.Value [n_param_vals - 1];
                for (int i = 1; i < n_param_vals; i++)
                {
                    IntPtr ptr = new IntPtr(param_values.ToInt64() + i * Marshal.SizeOf(typeof(Value)));
                    vals [i - 1]      = (Value)Marshal.PtrToStructure(ptr, typeof(Value));
                    args.Args [i - 1] = vals [i - 1].Val;
                }
                ClosureInvokedArgs ci_args = new ClosureInvokedArgs(__obj, args);
                closure.Invoke(ci_args);
                for (int i = 1; i < n_param_vals; i++)
                {
                    vals [i - 1].Update(args.Args [i - 1]);
                    IntPtr ptr = new IntPtr(param_values.ToInt64() + i * Marshal.SizeOf(typeof(Value)));
                    Marshal.StructureToPtr(vals [i - 1], ptr, false);
                }
                if (return_val == IntPtr.Zero || args.RetVal == null)
                {
                    return;
                }

                Value ret = (Value)Marshal.PtrToStructure(return_val, typeof(Value));
                ret.Val = args.RetVal;
                Marshal.StructureToPtr(ret, return_val, false);
            } catch (Exception e) {
                Console.WriteLine(message);
                ExceptionManager.RaiseUnhandledException(e, false);
            }
        }
コード例 #5
0
 internal void Free()
 {
     if (before_closure != null)
     {
         before_closure.Dispose();
         before_closure = null;
     }
     if (after_closure != null)
     {
         after_closure.Dispose();
         after_closure = null;
     }
     GC.SuppressFinalize(this);
 }
コード例 #6
0
 void ClosureDisposedCB(object o, EventArgs args)
 {
     if (o == before_closure)
     {
         before_closure.Disposed -= new EventHandler(ClosureDisposedHandler);
         before_closure.Invoked  -= new ClosureInvokedHandler(ClosureInvokedCB);
         before_closure           = null;
         before_handler           = null;
     }
     else if (o == after_closure)
     {
         after_closure.Disposed -= new EventHandler(ClosureDisposedHandler);
         after_closure.Invoked  -= new ClosureInvokedHandler(ClosureInvokedCB);
         after_closure           = null;
         after_handler           = null;
     }
 }
コード例 #7
0
        public void AddDelegate(Delegate d)
        {
            if (args_type == null)
            {
                args_type = d.Method.GetParameters()[1].ParameterType;
            }

            if (d.Method.IsDefined(typeof(ConnectBeforeAttribute), false))
            {
                before_handler = Delegate.Combine(before_handler, d);
                if (before_closure == null)
                {
                    if (marshaler == null)
                    {
                        before_closure = new SignalClosure(obj.Handle, name, args_type);
                    }
                    else
                    {
                        before_closure = new SignalClosure(obj.Handle, name, marshaler, this);
                    }
                    before_closure.Disposed += ClosureDisposedHandler;
                    before_closure.Invoked  += ClosureInvokedHandler;
                    before_closure.Connect(false);
                }
            }
            else
            {
                after_handler = Delegate.Combine(after_handler, d);
                if (after_closure == null)
                {
                    if (marshaler == null)
                    {
                        after_closure = new SignalClosure(obj.Handle, name, args_type);
                    }
                    else
                    {
                        after_closure = new SignalClosure(obj.Handle, name, marshaler, this);
                    }
                    after_closure.Disposed += ClosureDisposedHandler;
                    after_closure.Invoked  += ClosureInvokedHandler;
                    after_closure.Connect(true);
                }
            }
        }
コード例 #8
0
            unsafe static void MarshalCallback(IntPtr raw_closure, Value *return_val, uint n_param_vals, Value *param_values, IntPtr invocation_hint, IntPtr marshal_data)
            {
                SignalClosure closure = null;

                try {
                    closure = closures [raw_closure] as SignalClosure;
                    GLib.Object __obj = param_values [0].Val as GLib.Object;
                    if (__obj == null)
                    {
                        return;
                    }

                    if (closure.signal.args_type == typeof(EventArgs))
                    {
                        closure.Invoke(new ClosureInvokedArgs(__obj, EventArgs.Empty));
                        return;
                    }

                    SignalArgs args = FastActivator.CreateSignalArgs(closure.signal.args_type);
                    args.Args = new object [n_param_vals - 1];
                    for (int i = 1; i < n_param_vals; i++)
                    {
                        args.Args [i - 1] = param_values [i].Val;
                    }
                    ClosureInvokedArgs ci_args = new ClosureInvokedArgs(__obj, args);
                    closure.Invoke(ci_args);
                    for (int i = 1; i < n_param_vals; i++)
                    {
                        param_values [i].Update(args.Args [i - 1]);
                    }
                    if (return_val == null || args.RetVal == null)
                    {
                        return;
                    }

                    return_val->Val = args.RetVal;
                } catch (Exception e) {
                    if (closure != null)
                    {
                        Console.WriteLine("Marshaling {0} signal", closure.signal.name);
                    }
                    ExceptionManager.RaiseUnhandledException(e, false);
                }
            }
コード例 #9
0
        public void AddDelegate(Delegate d)
        {
            if (args_type == null)
            {
                args_type = d.Method.GetParameters()[1].ParameterType;
            }

            if (d.Method.IsDefined(typeof(ConnectBeforeAttribute), false))
            {
                tref.Target.BeforeSignals [name] = Delegate.Combine(tref.Target.BeforeSignals [name] as Delegate, d);
                if (before_closure == null)
                {
                    if (marshaler == null)
                    {
                        before_closure = new SignalClosure(this, args_type);
                    }
                    else
                    {
                        before_closure = new SignalClosure(this, marshaler);
                    }
                    before_closure.Disposed += ClosureDisposedHandler;
                    before_closure.Invoked  += ClosureInvokedHandler;
                    before_closure.Connect(false);
                }
            }
            else
            {
                tref.Target.AfterSignals [name] = Delegate.Combine(tref.Target.AfterSignals [name] as Delegate, d);
                if (after_closure == null)
                {
                    if (marshaler == null)
                    {
                        after_closure = new SignalClosure(this, args_type);
                    }
                    else
                    {
                        after_closure = new SignalClosure(this, marshaler);
                    }
                    after_closure.Disposed += ClosureDisposedHandler;
                    after_closure.Invoked  += ClosureInvokedHandler;
                    after_closure.Connect(true);
                }
            }
        }
コード例 #10
0
 public void RemoveDelegate(Delegate d)
 {
     if (d.Method.IsDefined(typeof(ConnectBeforeAttribute), false))
     {
         before_handler = Delegate.Remove(before_handler, d);
         if (before_handler == null && before_closure != null)
         {
             before_closure.Dispose();
             before_closure = null;
         }
     }
     else
     {
         after_handler = Delegate.Remove(after_handler, d);
         if (after_handler == null && after_closure != null)
         {
             after_closure.Dispose();
             after_closure = null;
         }
     }
 }
コード例 #11
0
        public void RemoveDelegate(Delegate d)
        {
            if (tref.Target == null)
            {
                return;
            }

            bool      before = d.Method.IsDefined(typeof(ConnectBeforeAttribute), false);
            Hashtable hash   = before ? tref.Target.BeforeSignals : tref.Target.AfterSignals;

            Delegate del = Delegate.Remove(hash [name] as Delegate, d);

            if (del != null)
            {
                hash [name] = del;
                return;
            }

            hash.Remove(name);
            if (before)
            {
                if (before_closure != null)
                {
                    before_closure.Dispose();
                    before_closure = null;
                }
            }
            else
            {
                if (after_closure != null)
                {
                    after_closure.Dispose();
                    after_closure = null;
                }
            }
        }
コード例 #12
0
ファイル: Signal.cs プロジェクト: knocte/gtk-sharp
 void ClosureDisposedCB(object o, EventArgs args)
 {
     if (o == before_closure) {
         before_closure.Disposed -= new EventHandler (ClosureDisposedHandler);
         before_closure.Invoked -= new ClosureInvokedHandler (ClosureInvokedCB);
         before_closure = null;
         before_handler = null;
     } else if (o == after_closure) {
         after_closure.Disposed -= new EventHandler (ClosureDisposedHandler);
         after_closure.Invoked -= new ClosureInvokedHandler (ClosureInvokedCB);
         after_closure = null;
         after_handler = null;
     }
 }
コード例 #13
0
ファイル: Signal.cs プロジェクト: knocte/gtk-sharp
 public void RemoveDelegate(Delegate d)
 {
     if (d.Method.IsDefined (typeof (ConnectBeforeAttribute), false)) {
         before_handler = Delegate.Remove (before_handler, d);
         if (before_handler == null && before_closure != null) {
             before_closure.Dispose ();
             before_closure = null;
         }
     } else {
         after_handler = Delegate.Remove (after_handler, d);
         if (after_handler == null && after_closure != null) {
             after_closure.Dispose ();
             after_closure = null;
         }
     }
 }
コード例 #14
0
ファイル: Signal.cs プロジェクト: knocte/gtk-sharp
        public void AddDelegate(Delegate d)
        {
            if (args_type == null)
                args_type = d.Method.GetParameters ()[1].ParameterType;

            if (d.Method.IsDefined (typeof (ConnectBeforeAttribute), false)) {
                before_handler = Delegate.Combine (before_handler, d);
                if (before_closure == null) {
                    if (marshaler == null)
                        before_closure = new SignalClosure (obj.Handle, name, args_type);
                    else
                        before_closure = new SignalClosure (obj.Handle, name, marshaler, this);
                    before_closure.Disposed += ClosureDisposedHandler;
                    before_closure.Invoked += ClosureInvokedHandler;
                    before_closure.Connect (false);
                }
            } else {
                after_handler = Delegate.Combine (after_handler, d);
                if (after_closure == null) {
                    if (marshaler == null)
                        after_closure = new SignalClosure (obj.Handle, name, args_type);
                    else
                        after_closure = new SignalClosure (obj.Handle, name, marshaler, this);
                    after_closure.Disposed += ClosureDisposedHandler;
                    after_closure.Invoked += ClosureInvokedHandler;
                    after_closure.Connect (true);
                }
            }
        }
コード例 #15
0
ファイル: Signal.cs プロジェクト: ystk/debian-gtk-sharp2
		public void RemoveDelegate (Delegate d)
		{
			if (tref.Target == null)
				return;

			if (d.Method.IsDefined (typeof (ConnectBeforeAttribute), false)) {
				tref.Target.BeforeSignals [name] = Delegate.Remove (tref.Target.BeforeSignals [name] as Delegate, d);
				if (tref.Target.BeforeSignals [name] == null && before_closure != null) {
					before_closure.Dispose ();
					before_closure = null;
				}
			} else {
				tref.Target.AfterSignals [name] = Delegate.Remove (tref.Target.AfterSignals [name] as Delegate, d);
				if (tref.Target.AfterSignals [name] == null && after_closure != null) {
					after_closure.Dispose ();
					after_closure = null;
				}
			}
		}
コード例 #16
0
ファイル: Signal.cs プロジェクト: ystk/debian-gtk-sharp2
		void ClosureDisposedCB (object o, EventArgs args)
		{
			if (o == before_closure) {
				before_closure.Disposed -= new EventHandler (ClosureDisposedHandler);
				before_closure.Invoked -= new ClosureInvokedHandler (ClosureInvokedCB);
				if (tref.Target != null)
					tref.Target.BeforeSignals.Remove (name);
				before_closure = null;
			} else if (o == after_closure) {
				after_closure.Disposed -= new EventHandler (ClosureDisposedHandler);
				after_closure.Invoked -= new ClosureInvokedHandler (ClosureInvokedCB);
				if (tref.Target != null)
					tref.Target.AfterSignals.Remove (name);
				after_closure = null;
			}

			if (before_closure == null && after_closure == null)
				tref.Signals.Remove (name);
		}