Beispiel #1
0
        static IntPtr CreateClosure(ClosureMarshal marshaler)
        {
            IntPtr raw_closure = g_closure_new_simple(Marshal.SizeOf(typeof(GClosure)), IntPtr.Zero);

            g_closure_set_marshal(raw_closure, marshaler);
            return(raw_closure);
        }
Beispiel #2
0
        void SetCallback(Delegate callback, ClosureMarshal callbackWrapper)
        {
            var gcHandle = GCHandle.Alloc(callback, GCHandleType.Weak);

            Marshal.WriteIntPtr(handle, (int)callbackGCHandleOffset, (IntPtr)gcHandle);
            var(callback_, notify_, userData_) = UnmanagedClosureMarshalDelegateFactory.CreateNotifyDelegate(callbackWrapper);
            g_closure_set_meta_marshal(handle, userData_, callback_);
            g_closure_add_invalidate_notifier(handle, userData_, notify_);
        }
Beispiel #3
0
        static void ConnectActivate(GLib.GType gtype)
        {
            if (ActivateMarshalCallback == null)
            {
                ActivateMarshalCallback = new ClosureMarshal(ActivateMarshal_cb);
            }

            GtkWidgetClass klass = GetClassStruct(gtype, false);

            klass.ActivateSignal = RegisterSignal("activate_signal", gtype, GLib.Signal.Flags.RunLast, GLib.GType.None, new GLib.GType [0], ActivateMarshalCallback);
            OverrideClassStruct(gtype, klass);
        }
Beispiel #4
0
		static uint RegisterSignal (string signal_name, GLib.GType gtype, GLib.Signal.Flags signal_flags, GLib.GType return_type, GLib.GType[] param_types, ClosureMarshal marshaler)
		{
			IntPtr[] native_param_types = new IntPtr [param_types.Length];
			for (int parm_idx = 0; parm_idx < param_types.Length; parm_idx++)
				native_param_types [parm_idx] = param_types [parm_idx].Val;

			IntPtr native_signal_name = GLib.Marshaller.StringToPtrGStrdup (signal_name);
			try {
				return g_signal_newv (native_signal_name, gtype.Val, signal_flags, CreateClosure (marshaler), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, return_type.Val, (uint) param_types.Length, native_param_types);
			} finally {
				GLib.Marshaller.Free (native_signal_name);
			}
		}
Beispiel #5
0
        static void ConnectActivate(GLib.GType gtype)
        {
            if (ActivateMarshalCallback == null)
            {
                ActivateMarshalCallback = new ClosureMarshal(ActivateMarshal_cb);
            }

            unsafe {
                uint *raw_ptr = (uint *)(((long)gtype.GetClassPtr()) + (long)class_abi.GetFieldOffset("activate_signal"));

                *raw_ptr = RegisterSignal("activate_signal", gtype, GLib.Signal.Flags.RunLast, GLib.GType.None,
                                          new GLib.GType [0], ActivateMarshalCallback);
            }
        }
Beispiel #6
0
        public Closure(SignalHandler <TArgs> callback, GLib.Object obj, string signal_name)
        {
            this.obj         = obj;
            this.callback    = callback;
            this.signal_name = signal_name;
            this.marshaller  = new ClosureMarshal(SignalMarshaller);

            IntPtr raw_closure = g_closure_new_simple(Marshal.SizeOf(typeof(GClosure)), IntPtr.Zero);

            g_closure_set_marshal(raw_closure, marshaller);
            g_signal_connect_closure(obj.Handle, Utils.StringToPtrGStrdup(signal_name), raw_closure, false);

            ClosureTable[raw_closure] = this;

            // Value[] values = GetValues();
            // Do we want to populate args here or in signal_marshaller?
            // Perhaps marshaller is better
            // TODO: Perf profiling
        }
Beispiel #7
0
		static extern void g_closure_set_marshal (IntPtr closure, ClosureMarshal marshaler);
Beispiel #8
0
        static uint RegisterSignal(string signal_name, GLib.GType gtype, GLib.Signal.Flags signal_flags, GLib.GType return_type, GLib.GType[] param_types, ClosureMarshal marshaler)
        {
            IntPtr[] native_param_types = new IntPtr [param_types.Length];
            for (int parm_idx = 0; parm_idx < param_types.Length; parm_idx++)
            {
                native_param_types [parm_idx] = param_types [parm_idx].Val;
            }

            IntPtr native_signal_name = GLib.Marshaller.StringToPtrGStrdup(signal_name);

            try {
                return(g_signal_newv(native_signal_name, gtype.Val, signal_flags, CreateClosure(marshaler), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, return_type.Val, (uint)param_types.Length, native_param_types));
            } finally {
                GLib.Marshaller.Free(native_signal_name);
            }
        }
Beispiel #9
0
 static extern void g_closure_set_marshal(IntPtr closure, ClosureMarshal marshaler);
Beispiel #10
0
        public static ValueTuple <UnmanagedClosureMarshal, UnmanagedClosureNotify, IntPtr> CreateNotifyDelegate(ClosureMarshal closureMarshal)
        {
            if (closureMarshal == null)
            {
                throw new ArgumentNullException(nameof(closureMarshal));
            }
            var userData = new UnmanagedClosureMarshalData {
                ClosureMarshal          = closureMarshal,
                UnmanagedClosureMarshal = UnmanagedClosureMarshal,
                UnmanagedClosureNotify  = UnmanagedClosureNotify,
            };
            var userData_ = GCHandle.Alloc(userData);

            return(userData.UnmanagedClosureMarshal, userData.UnmanagedClosureNotify, (IntPtr)userData_);
        }
Beispiel #11
0
		static IntPtr CreateClosure (ClosureMarshal marshaler) {
			IntPtr raw_closure = g_closure_new_simple (Marshal.SizeOf (typeof (GClosure)), IntPtr.Zero);
			g_closure_set_marshal (raw_closure, marshaler);
			return raw_closure;
		}
Beispiel #12
0
		static void ConnectActivate (GLib.GType gtype)
		{
			if (ActivateMarshalCallback == null)
				ActivateMarshalCallback = new ClosureMarshal (ActivateMarshal_cb);

			GtkWidgetClass klass = GetClassStruct (gtype, false);
			klass.ActivateSignal = RegisterSignal ("activate_signal", gtype, GLib.Signal.Flags.RunLast, GLib.GType.None, new GLib.GType [0], ActivateMarshalCallback);
			OverrideClassStruct (gtype, klass);
		}
Beispiel #13
0
		static extern IntPtr glibsharp_closure_new (ClosureMarshal marshaler, ClosureNotify notify, IntPtr gch);
 static extern IntPtr glibsharp_closure_new(ClosureMarshal marshaler, ClosureNotify notify, IntPtr gch);