public void SetContent(string label, bool useMnemonic, ImageDescription image, ContentPosition position) { Widget.UseUnderline = useMnemonic; this.image = image; if (label != null && label.Length == 0) label = null; Button b = (Button) Frontend; if (label != null && image.Backend == null && b.Type == ButtonType.Normal) { Widget.Label = label; return; } if (b.Type == ButtonType.Disclosure) { Widget.Label = null; Widget.Image = new Gtk.Arrow (Gtk.ArrowType.Down, Gtk.ShadowType.Out); Widget.Image.ShowAll (); return; } Gtk.Widget contentWidget = null; Gtk.Widget imageWidget = null; if (image.Backend != null) imageWidget = new ImageBox (ApplicationContext, image.WithDefaultSize (Gtk.IconSize.Button)); labelWidget = null; if (label != null && imageWidget == null) { contentWidget = labelWidget = new Gtk.Label (label); } else if (label == null && imageWidget != null) { contentWidget = imageWidget; } else if (label != null && imageWidget != null) { Gtk.Box box = position == ContentPosition.Left || position == ContentPosition.Right ? (Gtk.Box) new Gtk.HBox (false, 3) : (Gtk.Box) new Gtk.VBox (false, 3); labelWidget = new Gtk.Label (label) { UseUnderline = useMnemonic }; if (position == ContentPosition.Left || position == ContentPosition.Top) { box.PackStart (imageWidget, false, false, 0); box.PackStart (labelWidget, false, false, 0); } else { box.PackStart (labelWidget, false, false, 0); box.PackStart (imageWidget, false, false, 0); } contentWidget = box; } var expandButtonContent = false; if (b.Type == ButtonType.DropDown) { if (contentWidget != null) { Gtk.HBox box = new Gtk.HBox (false, 3); box.PackStart (contentWidget, true, true, 3); box.PackStart (new Gtk.Arrow (Gtk.ArrowType.Down, Gtk.ShadowType.Out), false, false, 0); contentWidget = box; expandButtonContent = true; } else contentWidget = new Gtk.Arrow (Gtk.ArrowType.Down, Gtk.ShadowType.Out); } if (contentWidget != null) { contentWidget.ShowAll (); Widget.Label = null; Widget.Image = contentWidget; var alignment = Widget.Child as Gtk.Alignment; if (alignment != null) { if (expandButtonContent) { var box = alignment.Child as Gtk.Box; if (box != null) { alignment.Xscale = 1; box.SetChildPacking (box.Children [0], true, true, 0, Gtk.PackType.Start); if (labelWidget != null) labelWidget.Xalign = 0; } } else if (position == ContentPosition.Left && (contentWidget is Gtk.Box)) { // in case the button is wider than its natural size and has text and an image on the left, // optimize its alignment to make the text more centered. // FIXME: more sophisticated size calculation alignment.Xalign = 0.475f; } } if (labelWidget != null) { labelWidget.UseUnderline = useMnemonic; if (customFont != null) labelWidget.ModifyFont (customFont); if (customLabelColor.HasValue) { labelWidget.SetForegroundColor (customLabelColor.Value); labelWidget.SetForegroundColor (Gtk.StateType.Prelight, customLabelColor.Value); } } } else Widget.Label = null; }
public void SetImage (ImageDescription image) { image = image.WithDefaultSize (Gtk.IconSize.Menu); statusItem.Pixbuf = ((GtkImage)image.Backend).GetBestFrame (context, Util.GetDefaultScaleFactor (), image.Size.Width, image.Size.Height, true); }
public void SetContent(string label, bool useMnemonic, ImageDescription image, ContentPosition position) { Widget.UseUnderline = useMnemonic; this.image = image; if (label != null && label.Length == 0) label = null; Button b = (Button) Frontend; if (label != null && image.Backend == null && b.Type == ButtonType.Normal) { Widget.Label = label; return; } if (b.Type == ButtonType.Disclosure) { Widget.Label = null; Widget.Image = new Gtk.Arrow (Gtk.ArrowType.Down, Gtk.ShadowType.Out); Widget.Image.ShowAll (); return; } Gtk.Widget contentWidget = null; Gtk.Widget imageWidget = null; if (image.Backend != null) imageWidget = new ImageBox (ApplicationContext, image.WithDefaultSize (Gtk.IconSize.Button)); if (label != null && imageWidget == null) { contentWidget = new Gtk.Label (label) { UseUnderline = useMnemonic }; } else if (label == null && imageWidget != null) { contentWidget = imageWidget; } else if (label != null && imageWidget != null) { Gtk.Box box = position == ContentPosition.Left || position == ContentPosition.Right ? (Gtk.Box) new Gtk.HBox (false, 3) : (Gtk.Box) new Gtk.VBox (false, 3); var lab = new Gtk.Label (label) { UseUnderline = useMnemonic }; if (position == ContentPosition.Left || position == ContentPosition.Top) { box.PackStart (imageWidget, false, false, 0); box.PackStart (lab, false, false, 0); } else { box.PackStart (lab, false, false, 0); box.PackStart (imageWidget, false, false, 0); } contentWidget = box; } if (b.Type == ButtonType.DropDown) { if (contentWidget != null) { Gtk.HBox box = new Gtk.HBox (false, 3); box.PackStart (contentWidget, true, true, 3); box.PackStart (new Gtk.VSeparator (), true, true, 0); box.PackStart (new Gtk.Arrow (Gtk.ArrowType.Down, Gtk.ShadowType.Out), false, false, 0); contentWidget = box; } else contentWidget = new Gtk.Arrow (Gtk.ArrowType.Down, Gtk.ShadowType.Out); } if (contentWidget != null) { contentWidget.ShowAll (); Widget.Label = null; Widget.Image = contentWidget; } else Widget.Label = null; }
public void SetContent (string label, bool useMnemonic, ImageDescription image, ContentPosition position) { Widget.UseUnderline = useMnemonic; this.image = image; if (label != null && label.Length == 0) label = null; Button b = (Button) Frontend; if (label != null && image.Backend == null && b.Type == ButtonType.Normal) { Widget.Label = label; return; } if (b.Type == ButtonType.Disclosure) { Widget.Label = null; Widget.Image = new Gtk.Arrow (Gtk.ArrowType.Down, Gtk.ShadowType.Out); Widget.Image.ShowAll (); return; } Gtk.Widget contentWidget = null; Gtk.Widget imageWidget = null; if (image.Backend != null) imageWidget = new ImageBox (ApplicationContext, image.WithDefaultSize (Gtk.IconSize.Button)); Gtk.Label labelWidget = null; if (label != null && imageWidget == null) { contentWidget = labelWidget = new Gtk.Label (label); } else if (label == null && imageWidget != null) { contentWidget = imageWidget; } else if (label != null && imageWidget != null) { Gtk.Box box = position == ContentPosition.Left || position == ContentPosition.Right ? (Gtk.Box) new Gtk.HBox (false, 3) : (Gtk.Box) new Gtk.VBox (false, 3); labelWidget = new Gtk.Label (label) { UseUnderline = useMnemonic }; if (position == ContentPosition.Left || position == ContentPosition.Top) { box.PackStart (imageWidget, false, false, 0); box.PackStart (labelWidget, false, false, 0); } else { box.PackStart (labelWidget, false, false, 0); box.PackStart (imageWidget, false, false, 0); } contentWidget = box; } var expandButtonContent = false; if (b.Type == ButtonType.DropDown) { if (contentWidget != null) { Gtk.HBox box = new Gtk.HBox (false, 3); box.PackStart (contentWidget, true, true, 3); box.PackStart (new Gtk.Arrow (Gtk.ArrowType.Down, Gtk.ShadowType.Out), false, false, 0); contentWidget = box; expandButtonContent = true; } else contentWidget = new Gtk.Arrow (Gtk.ArrowType.Down, Gtk.ShadowType.Out); } if (contentWidget != null) { contentWidget.ShowAll (); Widget.Label = null; Widget.Image = contentWidget; if (expandButtonContent) { var alignment = Widget.Child as Gtk.Alignment; if (alignment != null) { var box = alignment.Child as Gtk.Box; if (box != null) { alignment.Xscale = 1; box.SetChildPacking (box.Children [0], true, true, 0, Gtk.PackType.Start); if (labelWidget != null) labelWidget.Xalign = 0; } } } if (labelWidget != null) { labelWidget.UseUnderline = useMnemonic; if (customFont != null) labelWidget.ModifyFont (customFont); } } else Widget.Label = null; }