Exemple #1
0
                void MenuWillHighlightItem(NSMenu menu, NSMenuItem willHighlightItem)
                {
                    if (oldItem != null)
                    {
                        oldItem.FireDeselectedEvent();
                        oldItem = null;
                    }
                    if (willHighlightItem == null)
                    {
                        return;
                    }
                    int index = (int)menu.IndexOf(willHighlightItem);

                    if (index < 0)
                    {
                        return;
                    }
                    oldItem = this.menu.Items [index];
                    nfloat x = 0, y = 0;
                    var    locationAwareMenu = menu as NSLocationAwareMenu;

                    if (locationAwareMenu != null)
                    {
                        while (locationAwareMenu.Parent != null && locationAwareMenu.Parent.TryGetTarget(out var other))
                        {
                            locationAwareMenu = other;
                        }
                        x    = locationAwareMenu.Location.X;
                        y    = locationAwareMenu.Location.Y;
                        menu = locationAwareMenu;
                    }
                    oldItem.FireSelectedEvent(new Xwt.Rectangle(x, y, menu.Size.Width, menu.Size.Height));
                }
Exemple #2
0
            void MenuWillHighlightItem(NSMenu menu, NSMenuItem willHighlightItem)
            {
                if (oldItem != null)
                {
                    oldItem.FireDeselectedEvent();
                    oldItem = null;
                }
                if (willHighlightItem == null)
                {
                    return;
                }
                int index = (int)menu.IndexOf(willHighlightItem);

                if (index < 0)
                {
                    return;
                }
                oldItem = this.menu.Items [index];

                oldItem.FireSelectedEvent(new Xwt.Rectangle(lastOpenPositon.X, lastOpenPositon.Y, menu.Size.Width, menu.Size.Height));
            }
		static Gtk.MenuItem CreateMenuItem (ContextMenuItem item)
		{
			if (!item.Visible)
				return null;
			
			if (item.IsSeparator) {
				return new Gtk.SeparatorMenuItem ();
			}

			Gtk.MenuItem menuItem;
			if (item is RadioButtonContextMenuItem) {
				var radioItem = (RadioButtonContextMenuItem)item;
				menuItem = new Gtk.CheckMenuItem (item.Label) { Active = radioItem.Checked, DrawAsRadio = true };
			} else if (item is CheckBoxContextMenuItem) {
				var checkItem = (CheckBoxContextMenuItem)item;
				menuItem = new Gtk.CheckMenuItem (item.Label) { Active = checkItem.Checked };
			} else {
				menuItem = new Gtk.ImageMenuItem (item.Label);
			} 
			menuItem.Selected += delegate (object sender, EventArgs e) {
				var si = sender as Gtk.MenuItem;
				if (si == null || si.GdkWindow == null)
					return;
				int x, y;
				si.GdkWindow.GetOrigin (out x, out y);
				int rx, ry;
				IdeApp.Workbench.RootWindow.GdkWindow.GetOrigin (out rx, out ry);

				item.FireSelectedEvent (new Xwt.Rectangle (x - rx, y - ry, si.Allocation.Width, si.Allocation.Height));
			};
			menuItem.Deselected += delegate {
				item.FireDeselectedEvent ();
			};
			if (item.SubMenu != null && item.SubMenu.Items.Count > 0) {
				menuItem.Submenu = FromMenu (item.SubMenu, null);
			}
			else {
				menuItem.Activated += (sender, e) => item.Click ();
			}

			menuItem.Sensitive = item.Sensitive;

			var label = (Gtk.Label) menuItem.Child;
			label.UseUnderline = item.UseMnemonic;
			if (item.UseMnemonic)
				label.TextWithMnemonic = item.Label;

			if (item.Image != null) {
				Gtk.ImageMenuItem imageItem = menuItem as Gtk.ImageMenuItem;
				if (imageItem != null) {
					var img = new ImageView (item.Image);
					img.ShowAll ();
					imageItem.Image = img;
					Xwt.GtkBackend.GtkWorkarounds.ForceImageOnMenuItem (imageItem);
				}
			}

			return menuItem;
		}
        static Gtk.MenuItem CreateMenuItem(ContextMenuItem item)
        {
            if (!item.Visible)
            {
                return(null);
            }

            if (item.IsSeparator)
            {
                return(new Gtk.SeparatorMenuItem());
            }

            Gtk.MenuItem menuItem;
            if (item is RadioButtonContextMenuItem)
            {
                var radioItem = (RadioButtonContextMenuItem)item;
                menuItem = new Gtk.CheckMenuItem(item.Label)
                {
                    Active = radioItem.Checked, DrawAsRadio = true
                };
            }
            else if (item is CheckBoxContextMenuItem)
            {
                var checkItem = (CheckBoxContextMenuItem)item;
                menuItem = new Gtk.CheckMenuItem(item.Label)
                {
                    Active = checkItem.Checked
                };
            }
            else
            {
                menuItem = new Gtk.ImageMenuItem(item.Label);
            }
            menuItem.Selected += delegate(object sender, EventArgs e) {
                var si = sender as Gtk.MenuItem;
                if (si == null || si.GdkWindow == null)
                {
                    return;
                }
                int x, y;
                si.GdkWindow.GetOrigin(out x, out y);
                int rx, ry;
                IdeApp.Workbench.RootWindow.GdkWindow.GetOrigin(out rx, out ry);

                item.FireSelectedEvent(new Xwt.Rectangle(x - rx, y - ry, si.Allocation.Width, si.Allocation.Height));
            };
            menuItem.Deselected += delegate {
                item.FireDeselectedEvent();
            };
            if (item.SubMenu != null && item.SubMenu.Items.Count > 0)
            {
                menuItem.Submenu = FromMenu(item.SubMenu, null);
            }
            else
            {
                menuItem.Activated += (sender, e) => item.Click();
            }

            menuItem.Sensitive = item.Sensitive;

            var label = (Gtk.Label)menuItem.Child;

            label.UseUnderline = item.UseMnemonic;
            if (item.UseMnemonic)
            {
                label.TextWithMnemonic = item.Label;
            }

            if (item.Image != null)
            {
                Gtk.ImageMenuItem imageItem = menuItem as Gtk.ImageMenuItem;
                if (imageItem != null)
                {
                    var img = new ImageView(item.Image);
                    img.ShowAll();
                    imageItem.Image = img;
                    Xwt.GtkBackend.GtkWorkarounds.ForceImageOnMenuItem(imageItem);
                }
            }

            return(menuItem);
        }