public ButtonBarButton(IButtonBarButton button)
        {
            this.button = button;
            if (!button.Image.IsNull)
            {
                try {
                    SetImageFromResource(button.Image + ".png");
                } catch {
                    Image = button.Image.GetImageSource(Xwt.IconSize.Medium);
                }
            }

            VerticalContentAlignment = VerticalAlignment.Center;
            ToolTip    = button.Tooltip;
            IsEnabled  = button.Enabled;
            Visibility = button.Visible ? Visibility.Visible : Visibility.Collapsed;
            Margin     = new Thickness(3, 0, 3, 0);

            button.EnabledChanged += OnButtonEnabledChanged;
            button.VisibleChanged += OnButtonVisibleChanged;
            button.TooltipChanged += OnButtonTooltipChanged;
            button.ImageChanged   += OnButtonImageChanged;

            Click += OnButtonClicked;
        }
Ejemplo n.º 2
0
 protected override bool OnButtonReleaseEvent(EventButton evnt)
 {
     if (State == StateType.Selected && pushedButton != null)
     {
         pushedButton.NotifyPushed();
     }
     State        = StateType.Prelight;
     leaveState   = StateType.Normal;
     pushedButton = null;
     return(true);
 }
Ejemplo n.º 3
0
 protected override bool OnButtonPressEvent(EventButton evnt)
 {
     if (evnt.Button == 1)
     {
         pushedButton = VisibleButtons.FirstOrDefault(b => allocations [b].Contains(Allocation.X + (int)evnt.X, Allocation.Y + (int)evnt.Y));
         if (pushedButton != null && pushedButton.Enabled)
         {
             State = StateType.Selected;
         }
     }
     return(true);
 }
 void UpdateButton(IButtonBarButton button, int idx)
 {
     LoadIcon(button);
     if (button.Enabled != IsEnabled(idx))
     {
         SetEnabled(button.Enabled, idx);
     }
     if (button.Tooltip != Cell.GetToolTip(idx))
     {
         Cell.SetToolTip(button.Tooltip, idx);
     }
     SetNeedsDisplay();
 }
        void LoadIcon(IButtonBarButton button)
        {
            if (!indexMap.ContainsKey(button))
            {
                return;
            }
            NSImage img;

            if (button.Enabled)
            {
                img = ImageService.GetIcon(button.Image, Gtk.IconSize.Menu).ToNSImage();
            }
            else
            {
                img = ImageService.GetIcon(button.Image, Gtk.IconSize.Menu).WithStyles("disabled").ToNSImage();
            }
            SetImage(img, indexMap [button]);
        }
Ejemplo n.º 6
0
        public ButtonBarButton(IButtonBarButton button)
            : base(button.Image.IsNull ? null : button.Image.GetStockIcon().WithSize(Xwt.IconSize.Medium))
        {
            this.button = button;

            VerticalContentAlignment = VerticalAlignment.Center;
            ToolTip    = button.Tooltip;
            IsEnabled  = button.Enabled;
            Visibility = button.Visible ? Visibility.Visible : Visibility.Collapsed;
            Margin     = new Thickness(3, 0, 3, 0);

            button.EnabledChanged += OnButtonEnabledChanged;
            button.VisibleChanged += OnButtonVisibleChanged;
            button.TooltipChanged += OnButtonTooltipChanged;
            button.ImageChanged   += OnButtonImageChanged;

            Click += OnButtonClicked;
        }
        void UpdateButton(IButtonBarButton button, int idx)
        {
            var img = ImageService.GetIcon(button.Image, Gtk.IconSize.Menu);

            if (img.ToNSImage() != GetImage(idx))
            {
                SetImage(ImageService.GetIcon(button.Image, Gtk.IconSize.Menu).ToNSImage(), idx);
                SetNeedsDisplay();
            }
            if (button.Enabled != IsEnabled(idx))
            {
                SetEnabled(button.Enabled, idx);
                SetNeedsDisplay();
            }
            if (button.Tooltip != Cell.GetToolTip(idx))
            {
                Cell.SetToolTip(button.Tooltip, idx);
            }
        }
Ejemplo n.º 8
0
        void UpdateButton(IButtonBarButton button, int idx)
        {
            LoadIcon(button);
            if (button.Enabled != IsEnabled(idx))
            {
                SetEnabled(button.Enabled, idx);
            }

            if (button.Tooltip != Cell.GetToolTip(idx))
            {
                // SetToolTip is missing NullAllowed
                // https://github.com/xamarin/xamarin-macios/issues/6044
                Cell.SetToolTip(button.Tooltip ?? string.Empty, idx);
            }

            if (button.Title != GetLabel(idx))
            {
                SetLabel(button.Title, idx);
            }
            SetNeedsDisplay();
        }
Ejemplo n.º 9
0
        void LoadIcon(IButtonBarButton button)
        {
            if (!indexMap.ContainsKey(button))
            {
                return;
            }
            NSImage img;

            if (button.Enabled)
            {
                img = ImageService.GetIcon(button.Image, Gtk.IconSize.Menu).ToNSImage();
            }
            else
            {
                img = ImageService.GetIcon(button.Image, Gtk.IconSize.Menu).WithStyles("disabled").ToNSImage();
            }
            SetImage(img, indexMap [button]);

            // We need to set the width because if there is an image and a title set, then Cocoa uses the
            // title to set the width, even if the title isn't shown. We need to set the title for accessibility.
            SetWidth(ButtonBarContainer.SegmentWidth - 1, indexMap [button]);
        }
Ejemplo n.º 10
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            ScaleImages(Allocation.Height);

            using (var context = Gdk.CairoHelper.Create(evnt.Window)) {
                double x = Allocation.X, y = Allocation.Y;
                for (int i = 0; i < VisibleButtons.Length; i++)
                {
                    bool             nextIsSeparator  = (i < VisibleButtons.Length - 1 && VisibleButtons[i + 1].IsSeparator) || i == VisibleButtons.Length - 1;
                    bool             lastWasSeparator = (i > 0 && VisibleButtons[i - 1].IsSeparator) || i == 0;
                    IButtonBarButton button           = VisibleButtons [i];
                    if (button.IsSeparator)
                    {
                        if (!lastWasSeparator)
                        {
                            x += SeparatorSpacing;
                        }
                        continue;
                    }
                    Xwt.Drawing.Image[] images = State == StateType.Selected && pushedButton == button ? btnPressed : btnNormal;
                    Xwt.Drawing.Image   img    = images [lastWasSeparator ? 0 : nextIsSeparator ? 2 : 1];
                    context.DrawImage(this, img, x, y);

                    allocations [button] = new Gdk.Rectangle((int)x, (int)y, (int)img.Width, (int)img.Height);

                    var icon = ImageService.GetIcon(button.Image, IconSize.Menu);
                    if (!Sensitive || !button.Enabled)
                    {
                        icon = icon.WithAlpha(0.4);
                    }
                    context.DrawImage(this, icon, Math.Truncate(x + (img.Width - icon.Width) / 2), Math.Truncate(y + (img.Height - icon.Height) / 2));
                    x += img.Width;
                }
            }
            return(base.OnExposeEvent(evnt));
        }
Ejemplo n.º 11
0
		public ButtonBarButton (IButtonBarButton button)
			: base (button.Image.IsNull ? null : button.Image.GetStockIcon().WithSize(Xwt.IconSize.Medium))
		{
			this.button = button;

			VerticalContentAlignment = VerticalAlignment.Center;
			ToolTip = button.Tooltip;
			IsEnabled = button.Enabled;
			Visibility = button.Visible ? Visibility.Visible : Visibility.Collapsed;
			Margin = new Thickness(3, 0, 3, 0);

			button.EnabledChanged += OnButtonEnabledChanged;
			button.VisibleChanged += OnButtonVisibleChanged;
			button.TooltipChanged += OnButtonTooltipChanged;
			button.ImageChanged += OnButtonImageChanged;

			Click += OnButtonClicked;
		}
		public ButtonBarButton (IButtonBarButton button)
		{
			this.button = button;
			if (!button.Image.IsNull) {
				try {
					SetImageFromResource (button.Image + ".png");
				} catch {
					Image = button.Image.GetImageSource (Xwt.IconSize.Medium);
				}
			}

			VerticalContentAlignment = VerticalAlignment.Center;
			ToolTip = button.Tooltip;
			IsEnabled = button.Enabled;
			Visibility = button.Visible ? Visibility.Visible : Visibility.Collapsed;
			Margin = new Thickness(3, 0, 3, 0);

			button.EnabledChanged += OnButtonEnabledChanged;
			button.VisibleChanged += OnButtonVisibleChanged;
			button.TooltipChanged += OnButtonTooltipChanged;
			button.ImageChanged += OnButtonImageChanged;

			Click += OnButtonClicked;
		}
Ejemplo n.º 13
0
		void LoadIcon (IButtonBarButton button)
		{
			if (!indexMap.ContainsKey (button))
				return;
			NSImage img;
			if (button.Enabled)
				img = ImageService.GetIcon (button.Image, Gtk.IconSize.Menu).ToNSImage ();
			else
				img = ImageService.GetIcon (button.Image, Gtk.IconSize.Menu).WithStyles ("disabled").ToNSImage ();
			SetImage (img, indexMap [button]);
		}
Ejemplo n.º 14
0
		void UpdateButton (IButtonBarButton button, int idx)
		{
			LoadIcon (button);
			if (button.Enabled != IsEnabled (idx))
				SetEnabled (button.Enabled, idx);
			if (button.Tooltip != Cell.GetToolTip (idx))
				Cell.SetToolTip (button.Tooltip, idx);
			SetNeedsDisplay ();
		}
Ejemplo n.º 15
0
		protected override bool OnButtonReleaseEvent (EventButton evnt)
		{
			if (State == StateType.Selected && pushedButton != null) {
				pushedButton.NotifyPushed ();
			}
			State = StateType.Prelight;
			leaveState = StateType.Normal;
			pushedButton = null;
			return true;
		}
Ejemplo n.º 16
0
		protected override bool OnButtonPressEvent (EventButton evnt)
		{
			if (evnt.Button == 1) {
				pushedButton = VisibleButtons.FirstOrDefault (b => allocations [b].Contains (Allocation.X + (int)evnt.X, Allocation.Y + (int)evnt.Y));
				if (pushedButton != null && pushedButton.Enabled)
					State = StateType.Selected;
			}
			return true;
		}
Ejemplo n.º 17
0
		void UpdateButton (IButtonBarButton button, int idx)
		{
			var img = ImageService.GetIcon (button.Image, Gtk.IconSize.Menu);
			if (img.ToNSImage () != GetImage (idx)) {
				SetImage (ImageService.GetIcon (button.Image, Gtk.IconSize.Menu).ToNSImage (), idx);
				SetNeedsDisplay ();
			}
			if (button.Enabled != IsEnabled (idx)) {
				SetEnabled (button.Enabled, idx);
				SetNeedsDisplay ();
			}
			if (button.Tooltip != Cell.GetToolTip (idx))
				Cell.SetToolTip (button.Tooltip, idx);
		}