|
Class Lmenu |
Home |
|
This adds menu items to a menubar or popup menu and automatically creates popup sub-menus as children are added to Lmenu objects. Menus can contain any other Locana object but typically contains other Lmenu objects. Lmenu objects that contain children will automatically create and manage a Lmenu_window object that acts as a popup style sub-menu window and house all the children. In other words, Lmenu objects with children automatically become popup sub-menus and the popup sub-menu is handled by automatically creating a Lmenu_window object and putting all the children in the Lmenu_window object.
The position of the menu is automatically calculated based the position of the it’s text within it’s parent menu. The size of the popup window is always calculated based on its children during show_menu().
Here are some details on attributes that are specific to menu objects:
menuitem(:save, text=>'Save') menuitem(:saveAs, text=>'SaveAs') menuitem(:open, text=>'Open')
Example of a menu bar:
Lwindow.new(:TestMenus, :text=>'Test menus') {
menubar(:mMain, :sticky=>:nw, :text=>'') {
menu(:mFile, :text=>'File') {
menuitem(:mOpen, :text=>'Open')
menuitem(:mSave, :text=>'Save')
menuitem(:mSaveas, :text=>'Save As')
}
menu(:mEdit, :text=>'Edit') {
menuitem(:mCut, :text=>'Cut')
menuitem(:mCopy, :text=>'Copy')
menuitem(:mPaste, :text=>'Paste')
}
}
mMain.mFile.mOpen.on_click = %q{msgbox("File.Open was selected")}
mMain.mFile.mSave.on_click = %q{msgbox("File.save was selected")}
mMain.mFile.mSaveas.on_click = %q{msgbox("File.SaveAs was selected")}
mMain.mEdit.mCut.on_click = %q{msgbox("Edit.cut was selected")}
mMain.mEdit.mCopy.on_click = %q{msgbox("Edit.copy was selected")}
mMain.mEdit.mPaste.on_click = %q{msgbox("Edit.paste was selected")}
button(:b_ok, :sticky=>:se, :padx=>5, :pady=>5, :text => 'Ok')
b_ok.on_click = "close()" # this button will close the form
open
}
Locana::event_loop
Example of a popup menu:
Lwindow.new(:TestMenus, :text=>'Test menus') {
label(:l0, :sticky=>:nw, :pady=>10, :text=>'This tests menus - use right mouse click to see a popup menu')
menu_popup(:popUp) {
menuitem(:testWindows, :text=>'Test Windows', :value=>[:Editbox, :Listbox, :Packing, :Spanning])
menuseparator(:s1) # add a separator line
menu(:testImages) {
menuitem(:mOne, :text=>'Test one')
menuitem(:mTwo, :text=>'Test two')
}
}
popUp.testWindows.Editbox.on_click = %q{Locana::open(:TestEditBox)}
popUp.testWindows.Listbox.on_click = %q{Locana::open(:TestListBox)}
popUp.testWindows.Packing.on_click = %q{Locana::open(:TestPackint)}
popUp.testWindows.Spanning.on_click = %q{Locana::open(:TestSpanning)}
popUp.testImages.mOne.on_click = %q{msgbox("testImages.mOne was selected")}
popUp.testImages.mTwo.on_click = %q{msgbox("testImages.mTwo was selected")}
button(:b_ok, :sticky=>:se, :padx=>5, :pady=>5, :text => 'Ok')
b_ok.on_click = "close()" # this button will close the form
open
}
Locana::event_loop
It is based on the Lcontainer class. The :before, :after, :above, :below are ignored. For menubars, all objects use :after=>:prev. For popup menus, all objects use :below=>prev.
| Methods |
| Public Class methods |
| selected_menus() src |
Returns an array of all menus that are currently selected or highlighted.
| open_menus() src |
Returns an array of all currently open menus, sub-menus, and popup menus.
| sub_menu_indicator() src |
Returns the default bitmap used to indicate there is a sub-menu.
| menu_is_active?() src |
Returns true if a menu (popup or menubar) is active, otherwise returns false.
| set_on_mouse_rdn_object(new_object) src |
The on_mouse_rdn event calls this to remember the object under the right mouse click. This can be used with popup menus to operate on the object under the mouse when the popup menu is opened.
| on_mouse_rdn_object() src |
Returns the object under the last on_mouse_rdn event. This can be used with popup menus to operate on the object under the mouse when the popup menu is opened.
| hide_all() src |
Closes all open popup menus and sub-menus.
| Public Instance methods |
| include_objects() src |
Translates the :value attribute into sub-menus.
| is_menubar?() src |
Returns false.
| is_menu_popup?(owner_object=nil) src |
Returns true is self is a top-level popup menu. Returns false for sub-menus under the popup menu or in the menubar.
| default_border() src |
Returns the symbol to use as the default border for this object. Returns :none because menu items don’t have borders by default.
| parent_window() src |
Returns the window that this popup menu was triggered from or the window that contains the menubar.
| valid_attribute?(attribute, lvalue=nil) src |
Supports the :text attribute.
| text=(new_value) src |
Converts ’&’ (except ’& ’) to an accelerator.
| is_submenu_open?() src |
Returns true if the sub-menu for this menu item is open.
| close() src |
Closes the sub-menu associated with this object.
| show_menu(x=nil, y=nil) src |
Shows or opens the sub-menu associated with the menu item. If x and y are not provided, the position of the menu is calculated based on the location of the parent menu.
| hide_menu() src |
Hides the sub-menu associated with this menu item.
| on_click(levent=nil, &block) src |
If this object has a sub-menu, the sub-menu is opened and entered otherwise the on_click event is triggered for the object.
| paint_normal() src |
Paints the menu item.
| on_paint_border(levent=nil) src |
Draws or paints the sub-menu indicator in the border area if this object has a sub-menu.
| clientW() src |
Takes the sub-menu indicator into consideration because it is in the border or outer frame.
| screenX() src |
When the owner of this object is not a menubar, we need a more precise value based on the location of the popup window that contains this object.
| screenY() src |
When the owner of this object is not a menubar, we need a more precise value based on the location of the popup window that contains this object.
| pixel_width() src |
Returns the pixel width of the text in the object. This should take into consideration the font, size, and style of the object and its parents. It also takes the sub menu indicator into consideration.
| pixel_height() src |
Returns the pixel height of the text in the object. This should take into consideration the font, size, and style of the object and its parents.
| export(prefix='', all_objects=nil) src |
The export does not want to include all_objects in order to see the sub-menus. Needed because of how sub-menus are stored.
| add(object) src |
If a sub-menu (Lmenu_window) has not been created yet, one is created and object is added to the sub-menu. All children (sub-menus) are placed inside a Lmenu_window object rather than storing the children directly in the menu. This makes the Lmenu object a little more complicated than other objects but greatly simplified what is needed to get a menu item in a parent menu and manage the popup sub-menus.
| add_top(object) src |
If a sub-menu (Lmenu_window) has not been created yet, one is created and object is added to the sub-menu. All children (sub-menus) are placed inside a Lmenu_window object rather than storing the children directly in the menu. This makes the Lmenu object a little more complicated than other objects but greatly simplified what is needed to get a menu item in a parent menu and manage the popup sub-menus.
| sub_menu() src |
Returns the popup window object (Lmenu_window) containing the sub-menu for this object if it contains a sub-menu. Returns nil if this object does not have a sub-menu.
| children() src |
Forwarded to the sub-menu window for this object. All children (sub-menus) are placed inside a Lmenu_window object rather than storing the children directly in the menu. This makes the Lmenu object a little more complicated than other objects but greatly simplified what is needed to get a menu item in a parent menu and manage the popup sub-menus. the popup sub-menus.
| children=(new_objects) src |
Forwarded to the sub-menu window for this object since all children (sub-menus) are placed inside a newly created popup style window rather than storing the children directly in the menu.
| each_child(include_internal=nil) {|obj| ...} src |
Yields each child in self. Forwarded to the sub-menu window for this object since all children (sub-menus) are placed inside a newly created popup style window rather than storing the children directly in the menu.
| Seva Software |
Thank you for taking the time to visit this web page. I trust you found the information contained in this page useful.
Please email any questions, concerns, or issues with this web site to webmaster@sevasoftware.com.
Please remember Seva Software when your company would benefit from an experienced database architect and software engineer.