public static void FillMenu(Gtk.MenuShell menu_shell, Gnome.UIInfo uiinfo, Gtk.AccelGroup accel_group, bool uline_accels, int pos) { IntPtr native_uiinfo = GLib.Marshaller.StructureToPtrAlloc(uiinfo); gnome_app_fill_menu(menu_shell == null ? IntPtr.Zero : menu_shell.Handle, native_uiinfo, accel_group == null ? IntPtr.Zero : accel_group.Handle, uline_accels, pos); uiinfo = Gnome.UIInfo.New(native_uiinfo); Marshal.FreeHGlobal(native_uiinfo); }
private Gtk.Widget AddRecursively(Gtk.MenuShell shell, List <MenuLayout> menus, BasicWidgetType type) { Gtk.Widget toTest = null; AddRecursivelyAux(shell, menus, type, ref toTest, 0); if ((type == BasicWidgetType.MainMenuBar) || (type == BasicWidgetType.ContextMenu)) { return(shell); } return(toTest); }
void TransferProps(Gtk.MenuShell oldMenu, Gtk.MenuShell newMenu) { if (oldMenu.Visible) { newMenu.Show(); } if (!oldMenu.Sensitive) { newMenu.Sensitive = false; } }
private bool AddRecursivelyAux(Gtk.MenuShell shell, List <MenuLayout> menus, BasicWidgetType type, ref Gtk.Widget widget, int level) { if (menus.Count <= 0) { return(false); } foreach (MenuLayout menu in menus) { Gtk.MenuItem menuitem = null; if (menu is MenuSeparator) { menuitem = new Gtk.SeparatorMenuItem(); if (type == BasicWidgetType.ChildMenuSeparator) { widget = menuitem; } } else { menuitem = new Gtk.MenuItem(menu.Label); Gtk.Menu menushell = new Gtk.Menu(); if (AddRecursivelyAux(menushell, menu.SubMenus, type, ref widget, level + 1)) { menuitem.Submenu = menushell; if ((widget == null) && (level == 0)) { widget = menuitem; } } else { if (widget == null && type == BasicWidgetType.ChildMenu) { widget = menuitem; } } } shell.Append(menuitem); menuitem.Show(); } shell.ShowAll(); return(true); }
/// MenuItemType ISolidIDE.GetMenuItem <MenuItemType>(params string[] names) { Gtk.MenuShell menu = (this as ISolidIDE).GetMainMenu(); Gtk.MenuItem item = null; for (int i = 0; i < names.Length; i++) { item = null; foreach (Gtk.Widget w in menu.Children) { if (w.Name == names[i] + "Action") { item = w as Gtk.ImageMenuItem; if (i < names.Length - 1) { if (item.Submenu == null) { item.Submenu = new Gtk.Menu(); } menu = item.Submenu as Gtk.MenuShell; } break; } } if (item == null) { item = new MenuItemType(); Gtk.AccelLabel accelLabel = new Gtk.AccelLabel(""); accelLabel.TextWithMnemonic = names[i]; accelLabel.SetAlignment(0f, 0.5f); item.Add(accelLabel); accelLabel.AccelWidget = item; item.Name = names[i] + "Action"; menu.Append(item); if (i < names.Length - 1) { item.Submenu = new Gtk.Menu(); } menu = item.Submenu as Gtk.MenuShell; } } return(item as MenuItemType); }
/// <summary> /// Creates a menu item for command. /// </summary> /// <param name="command">The command for which a menu item is to be created.</param> /// <param name="stockItem">If non-Zero, defines the stock item to use for the command.</param> /// <param name="requiresParentCommand">If <c>true</c>, this command requires a parent menu item.</param> /// <param name="menuItemType">A specific type of menu item to use.</param> /// <param name="stateData">If not <c>null</c>, state data for the menu item being created.</param> /// <returns>The menu item for the command.</returns> public static Gtk.MenuItem CreateMenuItemForCommand(this VisualRelayCommand command, Gtk.StockItem stockItem, bool requiresParentCommand, System.Type menuItemType = null, object stateData = null) { System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(command.UniqueId), "Command's UniqueId is not defined."); Gtk.MenuItem menuItemVisual = null; // Menu items must have a valid parent command already defined. var parentCommand = (VisualRelayCommand)command.MenuParent; if (parentCommand != null) { Gtk.MenuShell parentMenuShell = null; if (parentCommand.MenuItem.IsEmpty) { parentMenuShell = parentCommand.Visual.AsType <Gtk.MenuShell>(); } else { parentMenuShell = parentCommand.MenuItem.NativeMenuItem.Submenu as Gtk.MenuShell; } if (parentMenuShell == null) { var group = parentCommand.GetCommandGroup(); if (group != null) { if (parentCommand.MenuItem.IsEmpty) { parentCommand.MenuItem = group.CreateMenuItemForCommand(parentCommand); } parentMenuShell = new Gtk.Menu() { Name = parentCommand.UniqueId }; parentCommand.Visual = parentMenuShell; parentCommand.MenuItem.NativeMenuItem.Submenu = parentMenuShell; } } menuItemVisual = command.CreateMenuItem(parentMenuShell, parentCommand, stockItem, menuItemType, stateData); } return(menuItemVisual); }
public void Initialize(object frontend) { menu = new Gtk.Menu (); menu.Visible = true; }
public void InitializeBackend(object frontend, ApplicationContext context) { menu = new Gtk.Menu(); menu.Visible = true; }
public void InitializeBackend (object frontend, ApplicationContext context) { menu = new Gtk.Menu (); menu.Visible = true; }
/// <summary> /// Creates a menu item for command. /// </summary> /// <param name="command">The command for which a menu item is to be created.</param> /// <param name="parentMenu">The menu to put the menu item into.</param> /// <param name="parentCommand">Parent command for the given command.</param> /// <param name="stockItem">If non-Zero, defines the stock item to use for the command.</param> /// <param name="menuItemType">A specific type of menu item to use.</param> /// <param name="stateData">If not <c>null</c>, state data for the menu item being created.</param> /// <returns>The menu item for the command.</returns> public static OSMenuItem CreateMenuItem(this VisualRelayCommand command, Gtk.MenuShell parentMenu, VisualRelayCommand parentCommand, Gtk.StockItem stockItem, System.Type menuItemType = null, object stateData = null) { var useDefaultMenuHandler = true; Gtk.MenuItem menuItemVisual; if (command.UniqueId == RootCommandGroup.MenuSeparatorCommand.UniqueId) { menuItemVisual = new Gtk.SeparatorMenuItem(); useDefaultMenuHandler = false; } else if (menuItemType == typeof(Gtk.CheckMenuItem)) { var checkMenuItem = new Gtk.CheckMenuItem(command.MenuItemName); checkMenuItem.Active = (bool)stateData; menuItemVisual = checkMenuItem; useDefaultMenuHandler = false; } else if ((command.SmallIcon != null) || (stockItem.StockId != Gtk.StockItem.Zero.StockId)) { if (stockItem.StockId == Gtk.StockItem.Zero.StockId) { menuItemVisual = new Gtk.ImageMenuItem(command.MenuItemName) { Image = new Gtk.Image(command.SmallIcon) }; if (Properties.Settings.Default.EnableMenuIcons) { // NOTE: This causes some internal errors if we try to draw stock items. So don't do it. menuItemVisual.ExposeEvent += ImageMenuItemHackExposeEvent; } } else { menuItemVisual = new Gtk.ImageMenuItem(stockItem.StockId, null); } } else { menuItemVisual = new Gtk.MenuItem(command.MenuItemName); } menuItemVisual.Name = command.UniqueId; menuItemVisual.SetValue(CommandGroup.AttachedCommandPropertyName, command); var submenu = command.Visual.AsType <Gtk.Menu>(); if ((submenu == null) && (parentMenu is Gtk.MenuBar) && command.Visual.IsEmpty) { submenu = new Gtk.Menu() { Name = parentCommand.UniqueId }; command.Visual = submenu; } menuItemVisual.Submenu = submenu; var insertLocation = FindInsertLocation(parentCommand, command, true); if ((insertLocation < 0) || (insertLocation >= parentMenu.Children.Length)) { parentMenu.Append(menuItemVisual); } else { parentMenu.Insert(menuItemVisual, insertLocation); } if (useDefaultMenuHandler && (menuItemVisual.Submenu == null)) { menuItemVisual.Activated += HandleCommand; } if (!string.IsNullOrEmpty(command.KeyboardShortcutKey)) { command.AddAccelerator(menuItemVisual, command.GetAcceleratorKey()); } menuItemVisual.ShowAll(); // because programmatically created, need to show ////DebugOutputIf(requiresParentCommand && (parentCommand.MenuItem.IsEmpty) && (parentCommand.Visual.IsEmpty), "Failed to create parent menu item for command: " + command.Name + "(" + command.UniqueId + ")"); ////DebugOutputIf(requiresParentCommand && (parentCommand == null) && (parentCommand.Visual.IsEmpty), "No parent menu item for command: " + command.Name + "(" + command.UniqueId + ")"); if (menuItemVisual != null) { var group = command.GetCommandGroup() as CommandGroup; if (group != null) { var context = group.GetCommandContext(command, null); menuItemVisual.SetValue(IFakeDependencyObjectHelpers.DataContextPropertyName, context); group.AttachCanExecuteChangeHandler(command); } } return(menuItemVisual); }
private void ConvertAndAddMenuItem(System.Windows.Forms.ToolStripItem item, Gtk.MenuShell gtkMenuShell) { if (item is System.Windows.Forms.ToolStripMenuItem) { var winformMenuItem = item as System.Windows.Forms.ToolStripMenuItem; // windows forms use '&' for mneumonic, gtk uses '_' var gtkMenuItem = new Gtk.ImageMenuItem(winformMenuItem.Text.Replace("&", "_")); if (winformMenuItem.Image != null) { MemoryStream memStream; var image = winformMenuItem.Image; if (image.Width != 16 || image.Height != 16) { var newImage = ResizeImage(image, 16, 16); memStream = new MemoryStream(newImage); } else { memStream = new MemoryStream(); image.Save(memStream, ImageFormat.Png); memStream.Position = 0; } gtkMenuItem.Image = new Gtk.Image(memStream); } gtkMenuItem.TooltipText = winformMenuItem.ToolTipText; gtkMenuItem.Visible = winformMenuItem.Visible; gtkMenuItem.Sensitive = winformMenuItem.Enabled; gtkMenuItem.Activated += (sender, e) => DBusBackgroundWorker.InvokeWinformsThread((Action)winformMenuItem.PerformClick); winformMenuItem.TextChanged += (sender, e) => DBusBackgroundWorker.InvokeGtkThread(() => { var label = gtkMenuItem.Child as Gtk.Label; if (label != null) { label.Text = winformMenuItem.Text; } } ); winformMenuItem.EnabledChanged += (sender, e) => DBusBackgroundWorker.InvokeGtkThread (() => gtkMenuItem.Sensitive = winformMenuItem.Enabled); winformMenuItem.VisibleChanged += (sender, e) => DBusBackgroundWorker.InvokeGtkThread (() => gtkMenuItem.Visible = winformMenuItem.Visible); gtkMenuItem.Show(); gtkMenuShell.Insert(gtkMenuItem, winformMenuItem.Owner.Items.IndexOf(winformMenuItem)); if (winformMenuItem.HasDropDownItems) { var subMenu = new Gtk.Menu(); foreach (System.Windows.Forms.ToolStripItem dropDownItem in winformMenuItem.DropDownItems) { ConvertAndAddMenuItem(dropDownItem, subMenu); } gtkMenuItem.Submenu = subMenu; winformMenuItem.DropDown.ItemAdded += (sender, e) => DBusBackgroundWorker.InvokeGtkThread (() => ConvertAndAddMenuItem(e.Item, subMenu)); } } else if (item is System.Windows.Forms.ToolStripSeparator) { var gtkSeparator = new Gtk.SeparatorMenuItem(); gtkSeparator.Show(); gtkMenuShell.Insert(gtkSeparator, item.Owner.Items.IndexOf(item)); } else { Debug.Fail("Unexpected menu item"); } }
public void AppendMenuitems(Gtk.MenuShell menushell) { gtk_im_multicontext_append_menuitems(Handle, menushell == null ? IntPtr.Zero : menushell.Handle); }
public void Initialize(object frontend) { menu = new Gtk.Menu(); menu.Visible = true; }
public void SetMenuBar(Gtk.MenuShell menu) { gtk_osxapplication_set_menu_bar(Handle, menu.Handle); }