Ejemplo n.º 1
0
        void HandleSelectedChanged(object obj, EventArgs args)
        {
            MenuItemWidget item     = obj as MenuItemWidget;
            bool           selected = item.Selected;

            UpdateSelected(-1);
            item.Selected = selected;
        }
Ejemplo n.º 2
0
        public void SetItems(MenuList items)
        {
            if (Container.Child != null)
            {
                foreach (Gtk.Widget widget in (Container.Child as VBox).Children)
                {
                    if (widget is MenuItemWidget)
                    {
                        (widget as MenuItemWidget).SelectedChanged -= HandleSelectedChanged;
                    }
                    widget.Dispose();
                    widget.Destroy();
                }
                Container.Remove(Container.Child);
            }

            VBox vbox = new VBox();

            Container.Add(vbox);

            Cairo.Color textColor;
            if (IsLight)
            {
                textColor = new Cairo.Color(0.1, 0.1, 0.1);
            }
            else
            {
                textColor = new Cairo.Color(1, 1, 1);
            }

            bool hasIcon = false;

            foreach (MenuItem item in items.DisplayItems)
            {
                if (item.ShowIcons)
                {
                    hasIcon = true;
                    break;
                }
            }

            bool first = true;
            int  width = 1;

            foreach (MenuItem item in items.DisplayItems)
            {
                if (item is SeparatorMenuItem)
                {
                    SeparatorWidget widget = new SeparatorWidget((item as SeparatorMenuItem).Title);
                    widget.TextColor = textColor;

                    if (first)
                    {
                        widget.DrawLine = false;
                    }

                    first = false;
                    vbox.PackStart(widget);
                }
                else
                {
                    MenuItemWidget menuItem = new MenuItemWidget(item);
                    menuItem.SelectedChanged += HandleSelectedChanged;
                    menuItem.TextColor        = textColor;
                    menuItem.MenuShowingIcons = hasIcon;

                    first = false;
                    vbox.PackStart(menuItem, false, false, 0);

                    width = Math.Max(width, menuItem.RequestedWidth);
                }
            }
            vbox.SetSizeRequest(width, -1);

            Container.ShowAll();
        }
Ejemplo n.º 3
0
		public void SetItems (MenuList items)
		{
			if (Container.Child != null) {
				foreach (Gtk.Widget widget in (Container.Child as VBox).Children) {
					if (widget is MenuItemWidget)
						(widget as MenuItemWidget).SelectedChanged -= HandleSelectedChanged;
					widget.Dispose ();
					widget.Destroy ();
				}
				Container.Remove (Container.Child);
			}
			
			VBox vbox = new VBox ();
			Container.Add (vbox);
			
			Cairo.Color textColor;
			if (IsLight) {
				textColor = new Cairo.Color (0.1, 0.1, 0.1);
			} else {
				textColor = new Cairo.Color (1, 1, 1);
			}
			
			bool hasIcon = false;
			foreach (MenuItem item in items.DisplayItems) {
				if (item.ShowIcons) {
					hasIcon = true;
					break;
				}
			}
			
			bool first = true;
			int width = 1;
			foreach (MenuItem item in items.DisplayItems) {
				if (item is SeparatorMenuItem) {
					SeparatorWidget widget = new SeparatorWidget ((item as SeparatorMenuItem).Title);
					widget.TextColor = textColor;
					
					if (first)
						widget.DrawLine = false;
					
					first = false;
					vbox.PackStart (widget);
				} else {
					MenuItemWidget menuItem = new MenuItemWidget (item);
					menuItem.SelectedChanged += HandleSelectedChanged;
					menuItem.TextColor = textColor;
					menuItem.MenuShowingIcons = hasIcon;
					
					first = false;
					vbox.PackStart (menuItem, false, false, 0);
					
					width = Math.Max (width, menuItem.RequestedWidth);
				}
			}
			vbox.SetSizeRequest (width, -1);
			
			Container.ShowAll ();
		}