Module WidgetWrapper::Menus::Menu
In: widget_wrapper/lib/wx_wrapper/menu.rb

Menu Syntax (Called after a menu bar block)

  menu "&File" do |item|
    item.add :new
    item.add :open
    item.separator
    item.add :save
    item.separator
    item.add :preview
    item.add :print
    item.separator
    item.add :close
    item.add :quit
  end

Default menu items you can add are: new, open, close, exit, quit, save, print, preview, about, undo, redo, cut, copy, paste, delete, selectall, preferences, find, replace

Default menu items have their operating system level icons loaded automatically.

Methods

add   default_items   get_icon   items   separator  

Public Instance methods

Creates a menu item on the menu. Example syntax:

  item.add :close

[Source]

     # File widget_wrapper/lib/wx_wrapper/menu.rb, line 120
120:       def add(item, options={})
121:         icon = options.include?(:icon) ? get_icon(options[:icon]) : default_items[item][:icon]
122:         
123:         # 1st argument is the icon id, the next is menu item text, and then the next is the help text
124:         args = []
125:         args << icon
126:         args << (options.include?(:item) ? options[:item] : default_items[item][:item])
127:         args << (options.include?(:help) ? options[:help] : default_items[item][:help])
128:         
129:         append(*args)
130:       end

[Source]

     # File widget_wrapper/lib/wx_wrapper/menu.rb, line 93
 93:       def default_items
 94:         { 
 95:           :new => { :icon => get_icon(:new), :item => "&New\tCtrl-N", :help => "Create a file" },
 96:           :open => { :icon => get_icon(:open), :item => "&Open\tCtrl-O", :help => "Open a file" }, 
 97:           :close => { :icon => get_icon(:close), :item => "&Close\tCtrl-W", :help => "Close the file" },
 98:           :exit => { :icon => get_icon(:exit), :item => "E&xit\tAlt-F4", :help => "Exit Application" },
 99:           :quit => { :icon => get_icon(:exit), :item => "&Quit\tCtrl-Q", :help => "Quit Application" },
100:           :save => { :icon => get_icon(:save), :item => "&Save\tCtrl-S", :help => "Save the file" },
101:           :print => { :icon => get_icon(:print), :item => "&Print...\tCtrl-P", :help => "Print the file" },
102:           :preview => { :icon => get_icon(:preview), :item => "Print Previe&w\tShift-Ctrl-P", :help => "Print preview the file" },
103:           :about => { :icon => get_icon(:about), :item => "&About\tF1", :help => "About" },
104:           :undo => { :icon => get_icon(:undo), :item => "&Undo\tCtrl+Z", :help => "Undo" },
105:           :redo => { :icon => get_icon(:redo), :item => "&Redo\tCtrl+Shift+Z", :help => "Redo" },
106:           :cut => { :icon => get_icon(:cut), :item => "Cu&t\tCtrl+X", :help => "Undo" },
107:           :copy => { :icon => get_icon(:copy), :item => "&Copy\tCtrl+C", :help => "Copy" },
108:           :paste => { :icon => get_icon(:paste), :item => "&Paste\tCtrl+V", :help => "Paste" },
109:           :delete => { :icon => get_icon(:delete), :item => "&Delete", :help => "Delete" },
110:           :selectall => { :icon => get_icon(:selectall), :item => "Select &All\tCtrl+A", :help => "Select All" },
111:           :preferences => { :icon => get_icon(:preferences), :item => "Pr&eferences", :help => "Preferences" },
112:           :find => { :icon => get_icon(:find), :item => "&Find...\tCtrl+F", :help => "Find" },
113:           :replace => { :icon => get_icon(:replace), :item => "&Replace...\tCtrl+H", :help => "Replace" }
114:         }
115:       end

TODO: PUT into another module

[Source]

     # File widget_wrapper/lib/wx_wrapper/menu.rb, line 147
147:       def get_icon(icon)
148:         Wx.const_get("ID_#{icon.to_s.upcase}")
149:       end

Lists the menu item objects for a given menu

[Source]

     # File widget_wrapper/lib/wx_wrapper/menu.rb, line 138
138:       def items(options={})
139:         items_list = (1..get_menu_item_count-1).collect do |position|
140:           value = find_item_by_position(position)
141:           value unless value.get_kind == -1 && !options.include?(:include_separators)
142:         end
143:         items_list.compact
144:       end

Creates a new separator for the menu

[Source]

     # File widget_wrapper/lib/wx_wrapper/menu.rb, line 133
133:       def separator
134:         append_separator
135:       end

[Validate]