static void TextInsertedSignalCallback(IntPtr arg0, IntPtr arg1, int arg2, ref int arg3, IntPtr gch) { Gtk.TextInsertedArgs args = new Gtk.TextInsertedArgs(); 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[3]; args.Args[0] = GLib.Marshaller.Utf8PtrToString(arg1); args.Args[1] = arg2; args.Args[2] = arg3; Gtk.TextInsertedHandler handler = (Gtk.TextInsertedHandler)sig.Handler; handler(GLib.Object.GetObject(arg0), args); } catch (Exception e) { GLib.ExceptionManager.RaiseUnhandledException(e, false); } try { arg3 = ((int)args.Args[2]); } catch (Exception) { Exception ex = new Exception("args.RetVal or 'out' property unset or set to incorrect type in Gtk.TextInsertedHandler callback"); GLib.ExceptionManager.RaiseUnhandledException(ex, true); // NOTREACHED: above call doesn't return. throw ex; } }
/// <summary> /// Detach all event handlers defined in ApsimNG from the widget. /// This procedure uses reflection to gain access to non-public properties and fields. /// The procedure is not entirely safe, in that it makes assumptions about the internal handling of event /// signalling in Gtk#. This may break in future versions if the Gtk# internals change. This sort of /// breakage has occurred with an earlier version of this routine. /// A "breakage" probably won't be immediately apparent, but may lead to memory leaks, as the main /// reason for having this routine is to remove references that can prevent garbage collection. /// </summary> /// <param name="widget">The widget.</param> public static void DetachHandlers(this Widget widget) { PropertyInfo signals = typeof(GLib.Object).GetProperty("Signals", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); FieldInfo afterHandler = typeof(GLib.Signal).GetField("after_handler", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); FieldInfo beforeHandler = typeof(GLib.Signal).GetField("before_handler", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); if (signals != null && afterHandler != null && beforeHandler != null) { Dictionary <string, GLib.Signal> widgetSignals = (Dictionary <string, GLib.Signal>)signals.GetValue(widget); foreach (KeyValuePair <string, GLib.Signal> signal in widgetSignals) { if (signal.Key != "destroy") { GLib.Signal signalVal = signal.Value; Delegate afterDel = (Delegate)afterHandler.GetValue(signalVal); if (afterDel != null) { widget.RemoveSignalHandler(signal.Key, afterDel); } Delegate beforeDel = (Delegate)beforeHandler.GetValue(signalVal); if (beforeDel != null) { widget.RemoveSignalHandler(signal.Key, beforeDel); } } } } }
static bool VerifyAddChildSignalCallback(IntPtr arg0, IntPtr arg1, IntPtr arg2, IntPtr gch) { Cdn.VerifyAddChildArgs args = new Cdn.VerifyAddChildArgs(); 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[2]; args.Args[0] = GLib.Object.GetObject(arg1) as Cdn.Object; args.Args[1] = arg2; Cdn.VerifyAddChildHandler handler = (Cdn.VerifyAddChildHandler)sig.Handler; handler(GLib.Object.GetObject(arg0), args); } catch (Exception e) { GLib.ExceptionManager.RaiseUnhandledException(e, false); } try { if (args.RetVal == null) { return(false); } return((bool)args.RetVal); } catch (Exception) { Exception ex = new Exception("args.RetVal or 'out' property unset or set to incorrect type in Cdn.VerifyAddChildHandler callback"); GLib.ExceptionManager.RaiseUnhandledException(ex, true); // NOTREACHED: above call doesn't return. throw ex; } }
static void DragPerformDropSignalCallback(IntPtr inst, IntPtr arg0, IntPtr arg1, int arg2, IntPtr gch) { Gtk.DragPerformDropArgs args = new Gtk.DragPerformDropArgs(); 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[3]; args.Args[0] = GLib.FileAdapter.GetObject(arg0, false); if (arg1 == IntPtr.Zero) { args.Args[1] = null; } else { args.Args[1] = new GLib.List(arg1); } args.Args[2] = (Gdk.DragAction)arg2; Gtk.DragPerformDropHandler handler = (Gtk.DragPerformDropHandler)sig.Handler; handler(GLib.Object.GetObject(inst), args); } catch (Exception e) { GLib.ExceptionManager.RaiseUnhandledException(e, false); } }
static void ToggleSizeRequestedSignalCallback(IntPtr inst, out int arg0, IntPtr gch) { Gtk.ToggleSizeRequestedArgs args = new Gtk.ToggleSizeRequestedArgs(); 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]; Gtk.ToggleSizeRequestedHandler handler = (Gtk.ToggleSizeRequestedHandler)sig.Handler; handler(GLib.Object.GetObject(inst), args); } catch (Exception e) { GLib.ExceptionManager.RaiseUnhandledException(e, false); } try { arg0 = ((int)args.Args[0]); } catch (Exception) { Exception ex = new Exception("args.RetVal or 'out' property unset or set to incorrect type in Gtk.ToggleSizeRequestedHandler callback"); GLib.ExceptionManager.RaiseUnhandledException(ex, true); // NOTREACHED: above call doesn't return. throw ex; } }
static bool ChangeEventSignalCallback(IntPtr inst, out int arg0, int arg1, IntPtr gch) { GLib.ChangeEventArgs args = new GLib.ChangeEventArgs(); 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[2]; args.Args[1] = arg1; GLib.ChangeEventHandler handler = (GLib.ChangeEventHandler)sig.Handler; handler(GLib.Object.GetObject(inst), args); } catch (Exception e) { GLib.ExceptionManager.RaiseUnhandledException(e, false); } try { arg0 = ((int)args.Args[0]); if (args.RetVal == null) { return(false); } return((bool)args.RetVal); } catch (Exception) { Exception ex = new Exception("args.RetVal or 'out' property unset or set to incorrect type in GLib.ChangeEventHandler callback"); GLib.ExceptionManager.RaiseUnhandledException(ex, true); // NOTREACHED: above call doesn't return. throw ex; } }
static void SubworldRemovedSignalCallback(IntPtr arg0, IntPtr arg1, IntPtr gch) { GLib.Signal sig = ((GCHandle)gch).Target as GLib.Signal; if (sig == null) { throw new Exception("Unknown signal GC handle received " + gch); } RC.SubworldRemovedArgs args = new RC.SubworldRemovedArgs(); args.Args = new object[1]; args.Args[0] = GLib.Object.GetObject(arg1) as RC.World; RC.SubworldRemovedHandler handler = (RC.SubworldRemovedHandler)sig.Handler; handler(GLib.Object.GetObject(arg0), args); }
static void TransactStartSignalCallback(IntPtr arg0, int arg1, IntPtr gch) { GLib.Signal sig = ((GCHandle)gch).Target as GLib.Signal; if (sig == null) { throw new Exception("Unknown signal GC handle received " + gch); } RC.TransactStartArgs args = new RC.TransactStartArgs(); args.Args = new object[1]; args.Args[0] = arg1; RC.TransactStartHandler handler = (RC.TransactStartHandler)sig.Handler; handler(GLib.Object.GetObject(arg0), args); }
static void PlaylistEndSignalCallback(IntPtr arg0, IntPtr arg1, IntPtr gch) { GLib.Signal sig = ((GCHandle)gch).Target as GLib.Signal; if (sig == null) { throw new Exception("Unknown signal GC handle received " + gch); } TotemPlParser.PlaylistEndArgs args = new TotemPlParser.PlaylistEndArgs(); args.Args = new object[1]; args.Args[0] = GLib.Marshaller.Utf8PtrToString(arg1); TotemPlParser.PlaylistEndHandler handler = (TotemPlParser.PlaylistEndHandler)sig.Handler; handler(GLib.Object.GetObject(arg0), args); }
static void TransactProgressSignalCallback(IntPtr arg0, UIntPtr arg1, UIntPtr arg2, IntPtr gch) { GLib.Signal sig = ((GCHandle)gch).Target as GLib.Signal; if (sig == null) { throw new Exception("Unknown signal GC handle received " + gch); } RC.TransactProgressArgs args = new RC.TransactProgressArgs(); args.Args = new object[2]; args.Args[0] = (ulong)arg1; args.Args[1] = (ulong)arg2; RC.TransactProgressHandler handler = (RC.TransactProgressHandler)sig.Handler; handler(GLib.Object.GetObject(arg0), args); }
static void TransactStepSignalCallback(IntPtr arg0, int arg1, int arg2, IntPtr arg3, IntPtr gch) { GLib.Signal sig = ((GCHandle)gch).Target as GLib.Signal; if (sig == null) { throw new Exception("Unknown signal GC handle received " + gch); } RC.TransactStepArgs args = new RC.TransactStepArgs(); args.Args = new object[3]; args.Args[0] = arg1; args.Args[1] = (RC.PackmanStep)arg2; args.Args[2] = GLib.Marshaller.Utf8PtrToString(arg3); RC.TransactStepHandler handler = (RC.TransactStepHandler)sig.Handler; handler(GLib.Object.GetObject(arg0), args); }
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); } }
static void DeviceChangeSignalCallback(IntPtr arg0, int arg1, IntPtr gch) { DeviceChangeArgs args = new DeviceChangeArgs(); 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] = arg1; DeviceChangeHandler handler = (DeviceChangeHandler)sig.Handler; handler(GLib.Object.GetObject(arg0), args); } catch (Exception e) { GLib.ExceptionManager.RaiseUnhandledException(e, false); } }
static void ErrorSignalCallback(IntPtr arg0, IntPtr arg1, IntPtr gch) { ErrorArgs args = new ErrorArgs(); 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] = GLib.Marshaller.Utf8PtrToString(arg1); ErrorHandler handler = (ErrorHandler)sig.Handler; handler(GLib.Object.GetObject(arg0), args); } catch (Exception e) { GLib.ExceptionManager.RaiseUnhandledException(e, false); } }
static void PoppedUpSignalCallback(IntPtr inst, IntPtr arg0, IntPtr arg1, bool arg2, bool arg3, IntPtr gch) { Gtk.PoppedUpArgs args = new Gtk.PoppedUpArgs(); 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[4]; args.Args[0] = arg0; args.Args[1] = arg1; args.Args[2] = arg2; args.Args[3] = arg3; Gtk.PoppedUpHandler handler = (Gtk.PoppedUpHandler)sig.Handler; handler(GLib.Object.GetObject(inst), args); } catch (Exception e) { GLib.ExceptionManager.RaiseUnhandledException(e, false); } }
static void RowDeletedSignalCallback(IntPtr arg0, IntPtr arg1, IntPtr gch) { GLib.Signal sig = ((GCHandle)gch).Target as GLib.Signal; if (sig == null) { throw new Exception("Unknown signal GC handle received " + gch); } Gtk.RowDeletedArgs args = new Gtk.RowDeletedArgs(); args.Args = new object[1]; if (arg1 == IntPtr.Zero) { args.Args[0] = null; } else { args.Args[0] = new Gtk.TreePath(arg1); } Gtk.RowDeletedHandler handler = (Gtk.RowDeletedHandler)sig.Handler; handler(GLib.Object.GetObject(arg0), args); }
static void RowsReorderedSignalCallback(IntPtr arg0, IntPtr arg1, ref Gtk.TreeIter arg2, out int arg3, IntPtr gch) { GLib.Signal sig = ((GCHandle)gch).Target as GLib.Signal; if (sig == null) { throw new Exception("Unknown signal GC handle received " + gch); } Gtk.RowsReorderedArgs args = new Gtk.RowsReorderedArgs(); args.Args = new object[3]; if (arg1 == IntPtr.Zero) { args.Args[0] = null; } else { args.Args[0] = new Gtk.TreePath(arg1); } args.Args[1] = arg2; Gtk.RowsReorderedHandler handler = (Gtk.RowsReorderedHandler)sig.Handler; handler(GLib.Object.GetObject(arg0), args); arg3 = ((int)args.Args[2]); }
static void RowsReorderedSignalCallback(IntPtr arg0, IntPtr arg1, IntPtr arg2, IntPtr arg3, IntPtr gch) { Gtk.RowsReorderedArgs args = new Gtk.RowsReorderedArgs(); try { GLib.Signal sig = ((GCHandle)gch).Target as GLib.Signal; if (sig == null) { throw new Exception("Unknown signal GC handle received " + gch); } TreeModelSort sender = GLib.Object.GetObject(arg0) as TreeModelSort; args.Args = new object[3]; args.Args[0] = arg1 == IntPtr.Zero ? null : (Gtk.TreePath)GLib.Opaque.GetOpaque(arg1, typeof(Gtk.TreePath), false); args.Args[1] = Gtk.TreeIter.New(arg2); int child_cnt = arg2 == IntPtr.Zero ? sender.IterNChildren() : sender.IterNChildren((TreeIter)args.Args[1]); int[] new_order = new int [child_cnt]; Marshal.Copy(arg3, new_order, 0, child_cnt); args.Args[2] = new_order; Gtk.RowsReorderedHandler handler = (Gtk.RowsReorderedHandler)sig.Handler; handler(sender, args); } catch (Exception e) { GLib.ExceptionManager.RaiseUnhandledException(e, false); } }
static int DragActionRequestedSignalCallback(IntPtr inst, IntPtr arg0, IntPtr arg1, IntPtr arg2, IntPtr gch) { Gtk.DragActionRequestedArgs args = new Gtk.DragActionRequestedArgs(); 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[3]; args.Args[0] = GLib.Object.GetObject(arg0) as Gdk.DragContext; args.Args[1] = GLib.FileAdapter.GetObject(arg1, false); if (arg2 == IntPtr.Zero) { args.Args[2] = null; } else { args.Args[2] = new GLib.List(arg2); } Gtk.DragActionRequestedHandler handler = (Gtk.DragActionRequestedHandler)sig.Handler; handler(GLib.Object.GetObject(inst), args); } catch (Exception e) { GLib.ExceptionManager.RaiseUnhandledException(e, false); } try { return((int)((Gdk.DragAction)args.RetVal)); } catch (Exception) { Exception ex = new Exception("args.RetVal or 'out' property unset or set to incorrect type in Gtk.DragActionRequestedHandler callback"); GLib.ExceptionManager.RaiseUnhandledException(ex, true); // NOTREACHED: above call doesn't return. throw ex; } }
/// <summary> /// Initalize Gtk and DBus stuff /// </summary> private void GtkDBusInit() { /* setup ApplicationIndicator */ indicator = new ApplicationIndicator("keepass2-plugin-appindicator" + instanceCount++, "keepass2-locked", AppIndicator.Category.ApplicationStatus); #if DEBUG indicator.IconThemePath = Path.GetFullPath("Resources/icons"); #endif indicator.Title = PwDefs.ProductName; indicator.Status = AppIndicator.Status.Active; appIndicatorMenu = new Gtk.Menu(); var trayContextMenu = pluginHost.MainWindow.TrayContextMenu; // make copy of item list to prevent list changed exception when iterating var menuItems = new System.Windows.Forms.ToolStripItem[trayContextMenu.Items.Count]; trayContextMenu.Items.CopyTo(menuItems, 0); trayContextMenu.ItemAdded += (sender, e) => DBusBackgroundWorker.InvokeGtkThread (() => ConvertAndAddMenuItem(e.Item, appIndicatorMenu)); foreach (System.Windows.Forms.ToolStripItem item in menuItems) { ConvertAndAddMenuItem(item, appIndicatorMenu); } indicator.Menu = appIndicatorMenu; try { // This is a hack to get the about-to-show event from the dbusmenu // that is created by the appindicator. var getPropertyMethod = typeof(GLib.Object).GetMethod("GetProperty", BindingFlags.NonPublic | BindingFlags.Instance); var dbusMenuServer = (GLib.Value)getPropertyMethod.Invoke(indicator, new object[] { "dbus-menu-server" }); var rootNode = (GLib.Value)getPropertyMethod.Invoke(dbusMenuServer.Val, new object[] { "root-node" }); aboutToShowSignal = GLib.Signal.Lookup((GLib.Object)rootNode.Val, "about-to-show"); aboutToShowSignal.AddDelegate((EventHandler)OnAppIndicatorMenuShown); } catch (Exception ex) { Debug.Fail(ex.Message); // On desktops that don't support application indicators, libappinidicator // creates a fallback GtkStatusIcon. This event only fires in that case. appIndicatorMenu.Shown += OnAppIndicatorMenuShown; } // when mouse cursor is over application indicator, scroll up will untray // and scroll down will tray KeePass indicator.ScrollEvent += (o, args) => { /* Workaround for bug in mono/appindicator-sharp. * * args.Direction throws InvalidCastException * Can't cast args.Arg[1] to Gdk.ScrollDirection for some reason, so we * have to cast to uint first (that is the underlying data type) and * then cast to Gdk.ScrollDirection */ var scrollDirectionUint = (uint)args.Args[1]; var scrollDirection = (Gdk.ScrollDirection)scrollDirectionUint; var trayMenuItem = trayContextMenu.Items["m_ctxTrayTray"]; if (trayMenuItem.Enabled && (scrollDirection == Gdk.ScrollDirection.Up ^ pluginHost.MainWindow.Visible)) { DBusBackgroundWorker.InvokeWinformsThread (() => trayMenuItem.PerformClick()); } }; }