コード例 #1
0
 protected override bool OnButtonReleaseEvent(EventButton evnt)
 {
     if (!item.Disabled)
     {
         item.SendClick();
     }
     return(item.Disabled);
 }
コード例 #2
0
        protected override bool OnKeyPressEvent(EventKey evnt)
        {
            if (evnt.Key == Gdk.Key.Up)
            {
                do
                {
                    int selected = GetSelected() - 1;

                    if (selected < 0)
                    {
                        selected = NumberItems() - 1;
                    }

                    UpdateSelected(selected);
                } while (GetSelectedItem().item.Disabled);
            }
            else if (evnt.Key == Gdk.Key.Down)
            {
                do
                {
                    int selected = GetSelected() + 1;

                    if (selected > NumberItems() - 1)
                    {
                        selected = 0;
                    }

                    UpdateSelected(selected);
                } while (GetSelectedItem().item.Disabled);
            }
            else if (evnt.Key == Gdk.Key.Return && GetSelectedItem() != null)
            {
                MenuItem item = (GetSelectedItem() as MenuItemWidget).item;
                if (!item.Disabled)
                {
                    item.SendClick();
                    Hide();
                }
            }
            else if (evnt.Key == Gdk.Key.Escape)
            {
                Hide();
            }
            else
            {
                foreach (Gtk.Widget widget in (Container.Child as VBox).Children)
                {
                    if (widget is MenuItemWidget)
                    {
                        MenuItem item = (widget as MenuItemWidget).item;
                        if (evnt.KeyValue == item.Mnemonic)
                        {
                            if (!item.Disabled)
                            {
                                item.SendClick();
                                Hide();
                            }
                        }
                    }
                }
            }

            return(base.OnKeyPressEvent(evnt));
        }