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);
			} 

			if (item.SubMenu != null && item.SubMenu.Items.Count > 0) {
				menuItem.Submenu = FromMenu (item.SubMenu);
			}
			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;
					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;
		}
Ejemplo n.º 3
0
        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);
            }

            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);
        }