Class ::tycho::MenuSupport


Inherits: ::tycho::TWidget - Source File - Contents: itk_options - public methods - protected variables
This class defines functionality that supports a simple interface for creating, deleting, enabling, and disabling menus. Do not instantiate this class: use its subclasses, such as MenuBar and PopupMenu.

The MenuSupport code is designed with some assumptions about how menus will be used. First, all menus are accessed by name, including sub-menus. Second, as much as possible, menus and entries are accessed only by name -- for example, you can disable the menu entry "Undo" without knowing which menu the entry is contained in. This makes it easier for different widgets to manipulate a common set of menus, as well as requiring only one change rather than several if an entry needs to be moved. Third, the methods are very forgiving about "errors": for example, if you try to create an entry that already exists, then the new entry simply replaces the old one; if you try and disable a menu entry that does not exist, then the method silently does absolutely nothing, on the assumption that one piece of code somewhere deleted that entry and it's just easier for you not to have to know this (this is very easy to do with a class hierarchy in which menus are manipulated at different levels of the hierarchy.) What this means is that if you do make an error, such as disabling a non-existent menu entry, you will not be notified of the mistake, so be careful.


Itk_options

-font [::tycho::font
The font to use for displaying menus.
-padx 5
The horizontal menu button padding.
-pady 4
The vertical menu button padding.

Public constructs

Public Methods

add name inMenu args
Add a menu entry to the end of a menu. The method takes the name of the menu entry, the name of the menu in which the menu entry is to be added and other menu entry options. By default, the created entry is a "command" type entry, which executes the specified command when the entry is selected. The -type option can be used to choose a different type of entry. Some common options are:

Any other options understood by the add method of the Tk menu widget can be given, except for -menu and -label. If there is already an entry with the specified name, this method silently replaces the old entry with the new entry. Note that the options apply only to the newly created entry -- if creating a submenu, this means that only the options to the entry, not the menu itself, are set: use the menuconfigure method to set the options of the submenu.

addSeparator inMenu args
Add a separator to the end of the specified menu. The first argument is the name of the menu. The remaining arguments are passed unchanged to the Tk menu add separator command.
clear menu
Clear all entries from a menu. If the menu does not exist, then assume that it was already deleted, and just return.
delete name
Delete a menu or a menu entry. If the specified menu or entry does not exist, assume that it was already deleted and just return.
disable name
Disable a menu or a menu entry. Do nothing if the menu or entry does not exist.
empty name
Test if a menu is empty. Flag an error if the menu does not exist.
enable name
Enable a menu or a menu entry. Do nothing if the menu or entry does not exist.
entrycget name option
Get a configuration option of a menu entry. Flag an error if the entry does not exist.
entryconfigure name args
Get or configure options of a menu entry. Flag an error if the entry does not exist.
insert name before args
Insert an entry before the specified entry. An error is flagged if the entry to insert before does not exist. If the new entry already exists, delete it first so that the new one "replaces" the old one.
insertSeparator before
Insert a separator before the specified entry. An error is flagged if the specified entry does not exist.
menuname name
Return the menu in which an entry is contained. Flags an error if the entry doesn't exist.
menucget name option
Get a configuration option of a menu. Flag an error if the menu does not exist. (FIXME: Should it just exit silently?).
menuconfigure name args
Get or configure options of a menu. Flag an error if the menu does not exist. (FIXME: Should it just exit silently?).

Protected constructs

Protected Variables

itemtype
Each menu and menu entry has a type.
menupath
Each menu has an access path.
entrypath
Each entry is contained in a menu.

Index of classes



Author: Farhana Sheikh
Contributor: Edward A. Lee, John Reekie
Version: @(#)MenuSupport.itcl 1.17 11/20/96
Copyright: (c) 1995-1996 The Regents of the University of California.