Example #1
0
        public static Gtk.MenuItem MakeMenuItem(Gtk.Menu menu, string l, EventHandler e, bool enabled)
        {
            Gtk.MenuItem  i;
            Gtk.StockItem item = Gtk.StockItem.Zero;

            if (Gtk.StockManager.Lookup(l, ref item))
            {
                i = new Gtk.ImageMenuItem(l, new Gtk.AccelGroup());
            }
            else
            {
                i = new Gtk.MenuItem(l);
            }

            if (e != null)
            {
                i.Activated += e;
            }

            i.Sensitive = enabled;

            menu.Append(i);
            i.Show();

            return(i);
        }
Example #2
0
            public int Compare(object itemx, object itemy)
            {
                Gtk.StockItem x = (Gtk.StockItem)itemx;
                Gtk.StockItem y = (Gtk.StockItem)itemy;

                return(string.Compare(x.Label, y.Label));
            }
Example #3
0
        protected override void ReadProperties(ObjectReader reader, XmlElement elem)
        {
            Gtk.StockItem stockItem = Gtk.StockItem.Zero;
            bool          use_stock = (bool)GladeUtils.ExtractProperty(elem, "use_stock", false);

            if (use_stock)
            {
                string label = (string)GladeUtils.GetProperty(elem, "label", "");
                stockItem = Gtk.Stock.Lookup(label);
                if (stockItem.Label != null)
                {
                    GladeUtils.ExtractProperty(elem, "label", "");
                }
            }
            base.ReadProperties(reader, elem);

            if (stockItem.StockId != null)
            {
                Image = "stock:" + stockItem.StockId;
            }
            if (stockItem.Keyval != 0)
            {
                Accelerator = Gtk.Accelerator.Name(stockItem.Keyval, stockItem.Modifier);
            }
        }
Example #4
0
        static Image()
        {
            ArrayList tmpIds = new ArrayList();

            // We can't use Gtk.Stock.ListIds, because that returns different
            // values depending on what version of libgtk you have installed...
            foreach (PropertyInfo info in typeof(Gtk.Stock).GetProperties(BindingFlags.Public | BindingFlags.Static))
            {
                if (info.CanRead && info.PropertyType == typeof(string))
                {
                    tmpIds.Add(info.GetValue(null, null));
                }
            }
            foreach (PropertyInfo info in typeof(Gnome.Stock).GetProperties(BindingFlags.Public | BindingFlags.Static))
            {
                if (info.CanRead && info.PropertyType == typeof(string))
                {
                    tmpIds.Add(info.GetValue(null, null));
                }
            }

            ArrayList items = new ArrayList(), nonItems = new ArrayList();

            foreach (string id in tmpIds)
            {
                Gtk.StockItem item = Gtk.Stock.Lookup(id);
                if (item.StockId == null)
                {
                    nonItems.Add(id);
                }
                else
                {
                    item.Label = item.Label.Replace("_", "");
                    items.Add(item);
                }
            }
            items.Sort(new StockItemSorter());
            nonItems.Sort();

            stockIds    = new string[items.Count + nonItems.Count];
            stockLabels = new string[items.Count + nonItems.Count];
            for (int i = 0; i < items.Count; i++)
            {
                stockIds[i]    = ((Gtk.StockItem)items[i]).StockId;
                stockLabels[i] = ((Gtk.StockItem)items[i]).Label;
            }
            for (int i = 0; i < nonItems.Count; i++)
            {
                stockIds[i + items.Count]    = nonItems[i] as string;
                stockLabels[i + items.Count] = nonItems[i] as string;
            }

            Gtk.Icon.SizeLookup(Gtk.IconSize.Button, out imgWidth, out imgHeight);
        }
Example #5
0
        public Gtk.StockItem Copy()
        {
            IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(this));

            System.Runtime.InteropServices.Marshal.StructureToPtr(this, this_as_native, false);
            IntPtr raw_ret = gtk_stock_item_copy(this_as_native);

            Gtk.StockItem ret = Gtk.StockItem.New(raw_ret);
            ReadNative(this_as_native, ref this);
            System.Runtime.InteropServices.Marshal.FreeHGlobal(this_as_native);
            return(ret);
        }
Example #6
0
        public static bool Lookup(string stock_id, ref Gtk.StockItem item)
        {
            ConstStockItem const_item;
            IntPtr         native_id = GLib.Marshaller.StringToPtrGStrdup(stock_id);
            bool           found     = gtk_stock_lookup(native_id, out const_item);

            GLib.Marshaller.Free(native_id);
            if (!found)
            {
                return(false);
            }
            item = (StockItem)const_item;
            return(true);
        }
Example #7
0
		public static Gtk.StockItem Lookup (string stock_id) {
			ConstStockItem const_item;

			IntPtr native_id = GLib.Marshaller.StringToPtrGStrdup (stock_id);
			bool result = gtk_stock_lookup (native_id, out const_item);
			GLib.Marshaller.Free (native_id);
			if (!result)
				return Gtk.StockItem.Zero;

			Gtk.StockItem item = new Gtk.StockItem ();
			item.StockId = GLib.Marshaller.Utf8PtrToString (const_item.StockId);
			item.Label = GLib.Marshaller.Utf8PtrToString (const_item.Label);
			item.Modifier = const_item.Modifier;
			item.Keyval = const_item.Keyval;
			item.TranslationDomain = GLib.Marshaller.Utf8PtrToString (const_item.TranslationDomain);
			return item;
		}
Example #8
0
        public static Gtk.StockItem Lookup(string stock_id)
        {
            ConstStockItem const_item;

            IntPtr native_id = GLib.Marshaller.StringToPtrGStrdup(stock_id);
            bool   result    = gtk_stock_lookup(native_id, out const_item);

            GLib.Marshaller.Free(native_id);
            if (!result)
            {
                return(Gtk.StockItem.Zero);
            }

            Gtk.StockItem item = new Gtk.StockItem();
            item.StockId           = GLib.Marshaller.Utf8PtrToString(const_item.StockId);
            item.Label             = GLib.Marshaller.Utf8PtrToString(const_item.Label);
            item.Modifier          = const_item.Modifier;
            item.Keyval            = const_item.Keyval;
            item.TranslationDomain = GLib.Marshaller.Utf8PtrToString(const_item.TranslationDomain);
            return(item);
        }
Example #9
0
        public MessageDialog()
        {
            Resizable    = false;
            HasSeparator = false;
            BorderWidth  = 12;

            label            = new Gtk.Label();
            label.LineWrap   = true;
            label.Selectable = true;
            label.UseMarkup  = true;
            label.SetAlignment(0.0f, 0.0f);

            secondaryLabel            = new Gtk.Label();
            secondaryLabel.LineWrap   = true;
            secondaryLabel.Selectable = true;
            secondaryLabel.UseMarkup  = true;
            secondaryLabel.SetAlignment(0.0f, 0.0f);

            icon = new Gtk.Image(Gtk.Stock.DialogInfo, Gtk.IconSize.Dialog);
            icon.SetAlignment(0.5f, 0.0f);

            Gtk.StockItem item = Gtk.Stock.Lookup(icon.Stock);
            Title = item.Label;

            Gtk.HBox hbox = new Gtk.HBox(false, 12);
            Gtk.VBox vbox = new Gtk.VBox(false, 12);

            vbox.PackStart(label, false, false, 0);
            vbox.PackStart(secondaryLabel, true, true, 0);

            hbox.PackStart(icon, false, false, 0);
            hbox.PackStart(vbox, true, true, 0);

            VBox.PackStart(hbox, false, false, 0);
            hbox.ShowAll();

            Buttons = Gtk.ButtonsType.OkCancel;
        }
        protected override void Initialize()
        {
            base.Initialize();
            string name = (string)Value;

            if (name != null)
            {
                Stetic.ObjectWrapper w       = Stetic.ObjectWrapper.Lookup(Instance);
                Stetic.IProject      project = w.Project;
                Gdk.Pixbuf           px      = project.IconFactory.RenderIcon(project, name, ImageSize);
                if (px != null)
                {
                    Image = px;
                    label = name;
                    return;
                }

                Gtk.StockItem item = Gtk.Stock.Lookup(name);
                label = item.Label != null && item.Label.Length > 0 ? item.Label : name;
                label = label.Replace("_", "");

                Gtk.IconSet iset = Gtk.IconFactory.LookupDefault(name);
                if (iset == null)
                {
                    Image = WidgetUtils.MissingIcon;
                }
                else
                {
                    Image = iset.RenderIcon(new Gtk.Style(), Gtk.TextDirection.Ltr, Gtk.StateType.Normal, Gtk.IconSize.Menu, null, "");
                }
            }
            else
            {
                Image = null;
                label = "";
            }
        }
Example #11
0
        void CreateControls()
        {
            if (node.Type == Gtk.UIManagerItemType.Separator)
            {
                Gtk.Widget sep;
                if (parentMenu.IsTopMenu)
                {
                    sep = new Gtk.VSeparator();
                    sep.WidthRequest = 6;
                }
                else
                {
                    sep = new Gtk.HSeparator();
                    sep.HeightRequest = 6;
                }
                Add(sep);
                ShowAll();
                return;
            }
            else
            {
                if (Child != null && Child is Gtk.Separator)
                {
                    Remove(Child);
                }
            }

            if (node.Action == null)
            {
                return;
            }

            bool isGlobal = wrapper != null && wrapper.Project.ActionGroups.IndexOf(node.Action.ActionGroup) != -1;

            Gtk.Action gaction = node.Action.GtkAction;
            bool       barItem = parentMenu.IsTopMenu;

            string text  = gaction.Label;
            string stock = gaction.StockId;

            if (barItem)
            {
                icon = null;
            }
            else if (node.Action.Type == Stetic.Wrapper.Action.ActionType.Radio)
            {
                icon = new CheckActionIcon(true, node.Action.Active);
            }
            else if (node.Action.Type == Stetic.Wrapper.Action.ActionType.Toggle)
            {
                icon = new CheckActionIcon(node.Action.DrawAsRadio, node.Action.Active);
            }

            if (stock != null)
            {
                Gtk.StockItem item = Gtk.Stock.Lookup(stock);
                if (text == null || text.Length == 0)
                {
                    text = item.Label;
                }

                if (item.Keyval != 0 && !editing && !barItem)
                {
                    Gtk.Label lac       = new Gtk.Label();
                    string    accelName = Gtk.Accelerator.Name(item.Keyval, item.Modifier).ToUpper();
                    accelName = accelName.Replace("<CONTROL>", "Ctrl+");
                    accelName = accelName.Replace("<SHIFT>", "Shift+");
                    accelName = accelName.Replace("<ALT>", "Alt+");
                    lac.Text  = accelName;
                    accel     = lac;
                }

                if (icon == null && !barItem)
                {
                    icon = node.Action.CreateIcon(Gtk.IconSize.Menu);
                }
            }

            Gtk.Tooltips tooltips = null;
            if (editing)
            {
                tooltips = new Gtk.Tooltips();
            }

            if (editing && !isGlobal)
            {
                if (!barItem)
                {
                    Gtk.HBox bbox = new Gtk.HBox();
                    if (icon != null)
                    {
                        bbox.PackStart(icon, false, false, 0);
                    }
                    bbox.PackStart(new Gtk.Arrow(Gtk.ArrowType.Down, Gtk.ShadowType.In), false, false, 0);
                    Gtk.Button b = new Gtk.Button(bbox);
                    tooltips.SetTip(b, Catalog.GetString("Select action type"), "");
                    b.Relief            = Gtk.ReliefStyle.None;
                    b.ButtonPressEvent += OnSelectIcon;
                    icon = b;
                }
                else
                {
                    icon = null;
                }

                Gtk.Entry entry = new Gtk.Entry();
                entry.Text           = text;
                entry.Activated     += OnLabelActivated;
                entry.KeyPressEvent += OnEntryKeyPress;
                entry.HasFrame       = false;
                this.label           = entry;
                tooltips.SetTip(entry, Catalog.GetString("Action label"), "");
            }
            else
            {
                Gtk.Label label = new Gtk.Label(text);
                label.Xalign = 0;
                this.label   = label;
            }

            if (editing && wrapper != null)
            {
                // Add a button for creating / deleting a submenu
                Gdk.Pixbuf img;
                string     tip;
                if (node.Type != Gtk.UIManagerItemType.Menu)
                {
                    img = addMenuImage;
                    tip = Catalog.GetString("Add submenu (Ctrl+Right)");
                }
                else
                {
                    img = removeMenuImage;
                    tip = Catalog.GetString("Remove submenu (Ctrl+Left)");
                }

                Gtk.Button sb = new Gtk.Button(new Gtk.Image(img));
                tooltips.SetTip(sb, tip, "");
                sb.Relief   = Gtk.ReliefStyle.None;
                sb.Clicked += OnCreateDeleteSubmenu;

                // Make sure the button is alligned to the right of the column
                Gtk.HBox bbox = new Gtk.HBox();
                bbox.PackEnd(sb, false, false, 0);
                accel = bbox;
            }


            if (node.Type == Gtk.UIManagerItemType.Menu && !editing && !barItem)
            {
                Gtk.Arrow arrow = new Gtk.Arrow(Gtk.ArrowType.Right, Gtk.ShadowType.None);
                arrow.Xalign = 1;
                this.accel   = arrow;
            }

            if (itemSpacing > 0 && icon != null)
            {
                // Add some padding to the left of the icon
                Gtk.Alignment a = new Gtk.Alignment(0, 0.5f, 0, 0);
                a.LeftPadding = itemSpacing;
                a.Add(icon);
                icon = a;
            }
        }
Example #12
0
 public static void Add(Gtk.StockItem item)
 {
     gtk_stock_add(ref item, 1);
 }
Example #13
0
 public static void Add(Gtk.StockItem items, uint n_items)
 {
     gtk_stock_add(ref items, n_items);
 }
Example #14
0
 public static bool LookupItem(string stock_id, out Gtk.StockItem item)
 {
     item = StockItem.Zero;
     return(Lookup(stock_id, ref item));
 }
Example #15
0
 static void ReadNative(IntPtr native, ref Gtk.StockItem target)
 {
     target = New(native);
 }
Example #16
0
 static extern void gtk_stock_add(ref Gtk.StockItem item, uint n_items);
Example #17
0
        /// <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);
        }
Example #18
0
        /// <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);
        }