### In Files

- wx/classes/menu.rb

### Parent

Wx::Object

### Methods

- methods_with_optional_ids
- methods_with_optional_ids_and_pos

### Files

- wxruby2.lib

### Class Index

Quicksearch

- Wx
- Wx::AcceleratorTable
- Wx::Animation
- Wx::App
- Wx::ArtProvider
- Wx::AuiNotebook
- Wx::Bitmap
- Wx::BusyCursor
- Wx::CheckListBox
- Wx::Choice
- Wx::ClientDC
- Wx::Clipboard
- Wx::Colour
- Wx::ComboBox
- Wx::CommandEvent
- Wx::ControlWithItems
- Wx::DC
- Wx::Event
- Wx::EvtHandler
- Wx::Font
- Wx::Grid
- Wx::HelpController
- Wx::HelpControllerHelpProvider
- Wx::HelpProvider
- Wx::HtmlHelpController
- Wx::HtmlWindow
- Wx::Icon
- Wx::IconBundle
- Wx::Image
- Wx::ImageList
- Wx::KeywordConstructor
- Wx::KeywordConstructor::ClassMethods
- Wx::ListBox
- Wx::ListCtrl
- Wx::Locale
- Wx::MediaCtrl
- Wx::Menu
- Wx::MenuItem
- Wx::Notebook
- Wx::Object
- Wx::PaintDC
- Wx::Point
- Wx::PreviewFrame
- Wx::Rect
- Wx::RichTextCtrl
- Wx::SimpleHelpProvider
- Wx::Size
- Wx::Sizer
- Wx::Sound
- Wx::StandardPaths
- Wx::TextCtrl
- Wx::TextUrlEvent
- Wx::Timer
- Wx::ToolBar
- Wx::ToolBarTool
- Wx::TreeCtrl
- Wx::Window
- Wx::XmlResource
- Rumix
- Rumix::Application
- Rumix::Config
- Rumix::Registry
- Rumix::Widget
- Rumix::Widget::CheckOptionPanel
- Rumix::Widget::OptionItem
- Rumix::Widget::OptionPanel
- Rumix::Widget::RadioOptionPanel
- Rumix::Widget::TitleText
- ROpt
- ROpt::ArgumentParser
- ROpt::ParseResult
- Uconv
- Uconv::Error
- Enumerable
- File
- Ini
- Kernel
- Module
- Object
- Pathname
- WxConstructor
- WxRubyStyleAccessors

No matching classes.

# Wx::Menu

A single labelled list within a drop-down menu, or a popup menu

### Public Class Methods

methods_with_optional_ids(*meth_names) click to toggle source

In the standard WxWidgets API, the methods append, prepend, insert (and their variants) require a constant integer id as the identifier of the menu item. This is then used in event handling.

In WxRuby the use of explicit ids can be avoided in most cases, being a most unruby-ish practice. So, by analogy with the general use of Wx::Window classes and event handlers, where the id is implicit in the constructor, and the window can be passed direct to the event handler setup method, the below sets up a similar facility for adding items to Wx::Menu.

For all these methods, the only required argument is the string name of the menu item; a system-default id will be supplied if no explicit one is given. The return value of these methods in all cases is a Wx::MenuItem object, which can be passed directly as the first argument to an evt_menu handler.

    # File wx/classes/menu.rb, line 20
      def self.methods_with_optional_ids(*meth_names)
        class_eval do
          meth_names.each do | meth |
            old_meth = instance_method(meth)
            define_method(meth) do | *args |
              case args.first
                when Fixnum then old_meth.bind(self).call(*args)
                when String then old_meth.bind(self).call(Wx::ID_ANY, *args)
                when Wx::MenuItem then old_meth.bind(self).call(args.first)
              end
            end
          end
        end
      end

methods_with_optional_ids_and_pos(*meth_names) click to toggle source

This is much the same as above, except for insert and variants, which take an additional first argument, the position at which to insert the new item.

    # File wx/classes/menu.rb, line 43
      def self.methods_with_optional_ids_and_pos(*meth_names)
        class_eval do
          meth_names.each do | meth |
            old_meth = instance_method(meth)
            define_method(meth) do | pos, *args |
              case args.first
                when Fixnum then old_meth.bind(self).call(pos, *args)
                when String then old_meth.bind(self).call(pos, Wx::ID_ANY, *args)
                when Wx::MenuItem then old_meth.bind(self).call(pos, args.first)
              end
            end
          end
        end
      end

Disabled; run with $DEBUG to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.