home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>Tk::Menu - Create and manipulate Menu widgets</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Tk::Menu - Create and manipulate Menu widgets</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#standard options">STANDARD OPTIONS</A></LI>
- <LI><A HREF="#widgetspecific options">WIDGET-SPECIFIC OPTIONS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <UL>
-
- <LI><A HREF="#command entries">COMMAND ENTRIES</A></LI>
- <LI><A HREF="#separator entries">SEPARATOR ENTRIES</A></LI>
- <LI><A HREF="#checkbutton entries">CHECKBUTTON ENTRIES</A></LI>
- <LI><A HREF="#radiobutton entries">RADIOBUTTON ENTRIES</A></LI>
- <LI><A HREF="#cascade entries">CASCADE ENTRIES</A></LI>
- <LI><A HREF="#tearoff entries">TEAR-OFF ENTRIES</A></LI>
- <LI><A HREF="#menubars">MENUBARS</A></LI>
- <LI><A HREF="#special menus in menubars">SPECIAL MENUS IN MENUBARS</A></LI>
- <LI><A HREF="#separators in menubars">SEPARATORS IN MENUBARS</A></LI>
- <LI><A HREF="#clones">CLONES</A></LI>
- <LI><A HREF="#widget methods">WIDGET METHODS</A></LI>
- </UL>
-
- <LI><A HREF="#menu configurations">MENU CONFIGURATIONS</A></LI>
- <LI><A HREF="#default bindings">DEFAULT BINDINGS</A></LI>
- <LI><A HREF="#bugs">BUGS</A></LI>
- <LI><A HREF="#see also">SEE ALSO</A></LI>
- <LI><A HREF="#keywords">KEYWORDS</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>Tk::Menu - Create and manipulate Menu widgets</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <P> <EM>$menu</EM> = <EM>$parent</EM>-><STRONG>Menu</STRONG>(?<EM>options</EM>?);</P>
- <P>
- <HR>
- <H1><A NAME="standard options">STANDARD OPTIONS</A></H1>
- <P><TABLE CELLSPACING=0 CELLPADDING=0><TR><TD><STRONG>-activebackground</STRONG><TD><STRONG>-background</STRONG><TD><STRONG>-disabledforeground</STRONG><TD><STRONG>-relief</STRONG>
- <TR><TD><STRONG>-activeborderwidth</STRONG><TD><STRONG>-borderwidth</STRONG><TD><STRONG>-font</STRONG><TD><STRONG>-takefocus</STRONG>
- <TR><TD><STRONG>-activeforeground</STRONG><TD><STRONG>-cursor</STRONG><TD><STRONG>-foreground</STRONG></TABLE></P>
- <P>See <A HREF="../../../site/lib/Tk/options.html">the Tk::options manpage</A> for details of the standard options.</P>
- <P>
- <HR>
- <H1><A NAME="widgetspecific options">WIDGET-SPECIFIC OPTIONS</A></H1>
- <DL>
- <DT><STRONG><A NAME="item_Name%3A_postCommand">Name: <STRONG>postCommand</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Class%3A_Command">Class: <STRONG>Command</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Switch%3A_%2Dpostcommand">Switch: <STRONG>-postcommand</STRONG></A></STRONG><BR>
- <DD>
- If this option is specified then it provides a <A HREF="../../../site/lib/Tk/callbacks.html">callback</A> to execute
- each time the menu is posted. The callback is invoked by the <STRONG>post</STRONG>
- method before posting the menu. Note that in 8.0 on Macintosh
- and Windows, all commands in a menu systems are executed before any
- are posted. This is due to the limitations in the individual platforms'
- menu managers.
- <P></P>
- <DT><STRONG><A NAME="item_Name%3A_selectColor">Name: <STRONG>selectColor</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Class%3A_Background">Class: <STRONG>Background</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Switch%3A_%2Dselectcolor">Switch: <STRONG>-selectcolor</STRONG></A></STRONG><BR>
- <DD>
- For menu entries that are check buttons or radio buttons, this option
- specifies the color to display in the indicator when the check button
- or radio button is selected.
- <P></P>
- <DT><STRONG><A NAME="item_Name%3A_tearOff">Name: <STRONG>tearOff</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Class%3A_TearOff">Class: <STRONG>TearOff</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Switch%3A_%2Dtearoff">Switch: <STRONG>-tearoff</STRONG></A></STRONG><BR>
- <DD>
- This option must have a proper boolean value, which specifies
- whether or not the menu should include a tear-off entry at the
- top. If so, it will exist as entry 0 of the menu and the other
- entries will number starting at 1. The default
- menu bindings arrange for the menu to be torn off when the tear-off
- entry is invoked.
- <P></P>
- <DT><STRONG><A NAME="item_Name%3A_tearOffCommand">Name: <STRONG>tearOffCommand</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Class%3A_TearOffCommand">Class: <STRONG>TearOffCommand</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Switch%3A_%2Dtearoffcommand">Switch: <STRONG>-tearoffcommand</STRONG></A></STRONG><BR>
- <DD>
- If this option has a non-empty value, then it specifies a <A HREF="../../../site/lib/Tk/callbacks.html">perl/Tk callback</A>
- to invoke whenever the menu is torn off. The actual command will
- consist of the value of this option, followed by a space, followed
- by the name of the menu window, followed by a space, followed by
- the name of the name of the torn off menu window. For example, if
- the option's is ``<STRONG>a b</STRONG>'' and menu <STRONG>.x.y</STRONG> is torn off to
- create a new menu <STRONG>.x.tearoff1</STRONG>, then the command
- ``<STRONG>a b .x.y .x.tearoff1</STRONG>'' will be invoked.
- <P></P>
- <DT><STRONG><A NAME="item_Name%3A_title">Name: <STRONG>title</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Class%3A_Title">Class: <STRONG>Title</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Switch%3A_%2Dtitle">Switch: <STRONG>-title</STRONG></A></STRONG><BR>
- <DD>
- The string will be used to title the window created when this menu is
- torn off. If the title is NULL, then the window will have the title
- of the menubutton or the text of the cascade item from which this menu
- was invoked.
- <P></P>
- <DT><STRONG><A NAME="item_Name%3A_type">Name: <STRONG>type</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Class%3A_Type">Class: <STRONG>Type</STRONG></A></STRONG><BR>
- <DD>
- <DT><STRONG><A NAME="item_Switch%3A_%2Dtype">Switch: <STRONG>-type</STRONG></A></STRONG><BR>
- <DD>
- This option can be one of <STRONG>menubar</STRONG>, <STRONG>tearoff</STRONG>, or
- <STRONG>normal</STRONG>, and is set when the menu is created. While the string
- returned by the configuration database will change if this option is
- changed, this does not affect the menu widget's behavior. This is used
- by the cloning mechanism and is not normally set outside of the Tk
- library.
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>The <STRONG>Menu</STRONG> method creates a new top-level window (given
- by the $widget argument) and makes it into a menu widget.
- Additional
- options, described above, may be specified on the command line
- or in the option database
- to configure aspects of the menu such as its colors and font.
- The <STRONG>menu</STRONG> command returns its
- $widget argument. At the time this command is invoked,
- there must not exist a window named $widget, but
- $widget's parent must exist.</P>
- <P>A menu is a widget that displays a collection of one-line entries arranged
- in one or more columns. There exist several different types of entries,
- each with different properties. Entries of different types may be
- combined in a single menu. Menu entries are not the same as
- entry widgets. In fact, menu entries are not even distinct widgets;
- the entire menu is one widget.</P>
- <P>Menu entries are displayed with up to three separate fields.
- The main field is a label in the form of a text string,
- a bitmap, or an image, controlled by the <STRONG>-label</STRONG>,
- <STRONG>-bitmap</STRONG>, and <STRONG>-image</STRONG> options for the entry.
- If the <STRONG>-accelerator</STRONG> option is specified for an entry then a second
- textual field is displayed to the right of the label. The accelerator
- typically describes a keystroke sequence that may be typed in the
- application to cause the same result as invoking the menu entry.
- The third field is an <EM>indicator</EM>. The indicator is present only for
- checkbutton or radiobutton entries. It indicates whether the entry
- is selected or not, and is displayed to the left of the entry's
- string.</P>
- <P>In normal use, an entry becomes active (displays itself differently)
- whenever the mouse pointer is over the entry. If a mouse
- button is released over the entry then the entry is <EM>invoked</EM>.
- The effect of invocation is different for each type of entry;
- these effects are described below in the sections on individual
- entries.</P>
- <P>Entries may be <EM>disabled</EM>, which causes their labels
- and accelerators to be displayed
- with dimmer colors.
- The default menu bindings will not allow
- a disabled entry to be activated or invoked.
- Disabled entries may be re-enabled, at which point it becomes
- possible to activate and invoke them again.</P>
- <P>Whenever a menu's active entry is changed, a <<MenuSelect>> virtual
- event is sent to the menu. The active item can then be queried from
- the menu, and an action can be taken, such as setting
- context-sensitive help text for the entry.</P>
- <P>
- <H2><A NAME="command entries">COMMAND ENTRIES</A></H2>
- <P>The most common kind of menu entry is a command entry, which
- behaves much like a button widget. When a command entry is
- invoked, a callback is executed. The callback
- is specified with the <STRONG>-command</STRONG> option.</P>
- <P>
- <H2><A NAME="separator entries">SEPARATOR ENTRIES</A></H2>
- <P>A separator is an entry that is displayed as a horizontal dividing
- line. A separator may not be activated or invoked, and it has
- no behavior other than its display appearance.</P>
- <P>
- <H2><A NAME="checkbutton entries">CHECKBUTTON ENTRIES</A></H2>
- <P>A checkbutton menu entry behaves much like a checkbutton widget.
- When it is invoked it toggles back and forth between the selected
- and deselected states. When the entry is selected, a particular
- value is stored in a particular global variable (as determined by
- the <STRONG>-onvalue</STRONG> and <STRONG>-variable</STRONG> options for the entry); when
- the entry is deselected another value (determined by the
- <STRONG>-offvalue</STRONG> option) is stored in the global variable.
- An indicator box is displayed to the left of the label in a checkbutton
- entry. If the entry is selected then the indicator's center is displayed
- in the color given by the <STRONG>-selectcolor</STRONG> option for the entry;
- otherwise the indicator's center is displayed in the background color for
- the menu. If a <STRONG>-command</STRONG> option is specified for a checkbutton
- entry, then its value is evaluated each time the entry
- is invoked; this happens after toggling the entry's
- selected state.</P>
- <P>
- <H2><A NAME="radiobutton entries">RADIOBUTTON ENTRIES</A></H2>
- <P>A radiobutton menu entry behaves much like a radiobutton widget.
- Radiobutton entries are organized in groups of which only one
- entry may be selected at a time. Whenever a particular entry
- becomes selected it stores a particular value into a particular
- global variable (as determined by the <STRONG>-value</STRONG> and
- <STRONG>-variable</STRONG> options for the entry). This action
- causes any previously-selected entry in the same group
- to deselect itself.
- Once an entry has become selected, any change to the entry's
- associated variable will cause the entry to deselect itself.
- Grouping of radiobutton entries is determined by their
- associated variables: if two entries have the same associated
- variable then they are in the same group.
- An indicator diamond is displayed to the left of the label in each
- radiobutton entry. If the entry is selected then the indicator's
- center is displayed in the color given by the <STRONG>-selectcolor</STRONG> option
- for the entry;
- otherwise the indicator's center is displayed in the background color for
- the menu. If a <STRONG>-command</STRONG> option is specified for a radiobutton
- entry, then its value is evaluated each time the entry
- is invoked; this happens after selecting the entry.</P>
- <P>
- <H2><A NAME="cascade entries">CASCADE ENTRIES</A></H2>
- <P>A cascade entry is one with an associated menu (determined
- by the <STRONG>-menu</STRONG> option). Cascade entries allow the construction
- of cascading menus.
- The <STRONG>postcascade</STRONG> method can be used to post and unpost
- the associated menu just next to of the cascade entry.
- The associated menu must be a child of the menu containing
- the cascade entry (this is needed in order for menu traversal to
- work correctly).</P>
- <P>A cascade entry posts its associated menu by invoking</P>
- <P><EM>$menu</EM>-><STRONG>post</STRONG>(<EM>x,y</EM>)</P>
- <P>where <EM>menu</EM> is the path name of the associated menu, and <EM>x</EM>
- and <EM>y</EM> are the root-window coordinates of the upper-right
- corner of the cascade entry.
- <<<<<<< /home/perl5/NI-S/Tk8/doc/mann/tmp.7542.77
- On Unix, the lower-level menu is unposted by executing</P>
- <P><EM>$menu</EM>-><STRONG>unpost</STRONG></P>
- <P>where <EM>menu</EM> is the name of the associated menu.
- On other platforms, the platform's native code takes care of unposting the
- menu.</P>
- <P>If a <STRONG>-command</STRONG> option is specified for a cascade entry then it is
- evaluated
- whenever the entry is invoked.
- This is not
- supported on Windows.</P>
- <P>
- <H2><A NAME="tearoff entries">TEAR-OFF ENTRIES</A></H2>
- <P>A tear-off entry appears at the top of the menu if enabled with the
- <STRONG>tearOff</STRONG> option. It is not like other menu entries in that
- it cannot be created with the <STRONG>add</STRONG> method and
- cannot be deleted with the <STRONG>delete</STRONG> method.
- When a tear-off entry is created it appears as a dashed line at
- the top of the menu. Under the default bindings, invoking the
- tear-off entry causes a torn-off copy to be made of the menu and
- all of its submenus.</P>
- <P>
- <H2><A NAME="menubars">MENUBARS</A></H2>
- <P>Any menu can be set as a menubar for a toplevel window (see the
- <A HREF="../../../site/lib/Tk/Toplevel.html">Toplevel</A> constructor for syntax). On the Macintosh, whenever the
- toplevel is in front, this menu's cascade items will appear in the
- menubar across the top of the main monitor. On Windows and Unix, this
- menu's items will be displayed in a menubar accross the top of the
- window. These menus will behave according to the interface guidelines
- of their platforms. For every menu set as a menubar, a clone menu is
- made. See <A HREF="#clones">CLONES</A> for more information.</P>
- <P>
- <H2><A NAME="special menus in menubars">SPECIAL MENUS IN MENUBARS</A></H2>
- <P>Certain menus in a menubar will be treated specially. On the Macintosh,
- access to the special Apple and Help menus is provided. On Windows,
- access to the Windows System menu in each window is provided. On X Windows,
- a special right-justified help menu is provided. In all cases, these
- menus must be created with the command name of the menubar menu concatenated
- with the special name. So for a menubar named .menubar, on the Macintosh,
- the special menus would be .menubar.apple and .menubar.help; on Windows,
- the special menu would be .menubar.system; on X Windows, the help
- menu would be .menubar.help.</P>
- <P>When Tk sees an Apple menu on the Macintosh, that menu's contents make
- up the first items of the Apple menu on the screen whenever the window
- containing the menubar is in front. The menu is the
- first one that the user sees and has a title which is an Apple logo.
- After all of the Tk-defined items, the menu will have a separator,
- followed by all of the items in the user's Apple Menu Items folder.
- Since the System uses a different menu definition procedure for
- the Apple menu than Tk uses for its menus, and the system APIs do
- not fully support everything Tk tries to do, the menu item will only
- have its text displayed. No font attributes, images, bitmaps, or colors
- will be displayed. In addition, a menu with a tearoff item will have
- the tearoff item displayed as ``(TearOff)''.</P>
- <P>When Tk see a Help menu on the Macintosh, the menu's contents are
- appended to the standard help menu on the right of the user's menubar
- whenever the user's menubar is in front. The first items in the menu
- are provided by Apple. Similar to the Apple Menu, cusomization in this
- menu is limited to what the system provides.</P>
- <P>When Tk sees a System menu on Windows, its items are appended to the
- system menu that the menubar is attached to. This menu has an icon
- representing a spacebar, and can be invoked with the mouse or by typing
- Alt+Spacebar. Due to limitations in the Windows API, any font changes,
- colors, images, bitmaps, or tearoff images will not appear in the
- system menu.</P>
- <P>When Tk see a Help menu on X Windows, the menu is moved to be last in
- the menubar and is right justified.</P>
- <P>
- <H2><A NAME="separators in menubars">SEPARATORS IN MENUBARS</A></H2>
- <P>Separator entries are not displayed in menubars.
- The <EM>last</EM> separator entry causes remaining entries to be
- right justified.</P>
- <P>
- <H2><A NAME="clones">CLONES</A></H2>
- <P>When a menu is set as a menubar for a toplevel window, or when a menu
- is torn off, a clone of the menu is made. This clone is a menu widget
- in its own right, but it is a child of the original. Changes in the
- configuration of the original are reflected in the
- clone. Additionally, any cascades that are pointed to are also cloned
- so that menu traversal will work right. Clones are destroyed when
- either the tearoff or menubar goes away, or when the original menu is
- destroyed.</P>
- <P>
- <H2><A NAME="widget methods">WIDGET METHODS</A></H2>
- <P>The <STRONG>Menu</STRONG> method creates a widget object.
- This object supports the <STRONG>configure</STRONG> and <STRONG>cget</STRONG> methods
- described in <A HREF="../../../site/lib/Tk/options.html">the Tk::options manpage</A> which can be used to enquire and
- modify the options described above.
- The widget also inherits all the methods provided by the generic
- <A HREF="../../../site/lib/Tk/Widget.html">Tk::Widget</A> class, and the <A HREF="../../../site/lib/Tk/Wm.html">Tk::Wm</A> class.</P>
- <P>Many of the methods for a menu take as one argument an
- indicator of which entry of the menu to operate on. These
- indicators are called <EM>index</EM>es and may be specified in
- any of the following forms:</P>
- <DL>
- <DT><STRONG><A NAME="item_number"><EM>number</EM></A></STRONG><BR>
- <DD>
- Specifies the entry numerically, where 0 corresponds
- to the top-most entry of the menu, 1 to the entry below it, and
- so on.
- <P></P>
- <DT><STRONG><A NAME="item_active"><STRONG>active</STRONG></A></STRONG><BR>
- <DD>
- Indicates the entry that is currently active. If no entry is
- active then this form is equivalent to <STRONG>none</STRONG>. This form may
- not be abbreviated.
- <P></P>
- <DT><STRONG><A NAME="item_end"><STRONG>end</STRONG></A></STRONG><BR>
- <DD>
- Indicates the bottommost entry in the menu. If there are no
- entries in the menu then this form is equivalent to <STRONG>none</STRONG>.
- This form may not be abbreviated.
- <P></P>
- <DT><STRONG><A NAME="item_last"><STRONG>last</STRONG></A></STRONG><BR>
- <DD>
- Same as <STRONG>end</STRONG>.
- <P></P>
- <DT><STRONG><A NAME="item_none"><STRONG>none</STRONG></A></STRONG><BR>
- <DD>
- Indicates ``no entry at all''; this is used most commonly with
- the <STRONG>activate</STRONG> option to deactivate all the entries in the
- menu. In most cases the specification of <STRONG>none</STRONG> causes
- nothing to happen in the method.
- This form may not be abbreviated.
- <P></P>
- <DT><STRONG><A NAME="item_%40number"><STRONG>@</STRONG><EM>number</EM></A></STRONG><BR>
- <DD>
- In this form, <EM>number</EM> is treated as a y-coordinate in the
- menu's window; the entry closest to that y-coordinate is used.
- For example, ``<STRONG>@0</STRONG>'' indicates the top-most entry in the
- window.
- <P></P>
- <DT><STRONG><A NAME="item_pattern"><EM>pattern</EM></A></STRONG><BR>
- <DD>
- If the index doesn't satisfy one of the above forms then this
- form is used. <EM>Pattern</EM> is pattern-matched against the label of
- each entry in the menu, in order from the top down, until a
- matching entry is found.
- (In perl/Tk the matching is under review, but exact match
- should work.)
- <P></P></DL>
- <P>The following methods are possible for menu widgets:</P>
- <DL>
- <DT><STRONG><A NAME="item_activate"><EM>$menu</EM>-><STRONG>activate</STRONG>(<EM>index</EM>)</A></STRONG><BR>
- <DD>
- Change the state of the entry indicated by <EM>index</EM> to <STRONG>active</STRONG>
- and redisplay it using its active colors.
- Any previously-active entry is deactivated. If <EM>index</EM>
- is specified as <STRONG>none</STRONG>, or if the specified entry is
- disabled, then the menu ends up with no active entry.
- Returns an empty string.
- <P></P>
- <DT><STRONG><A NAME="item_add"><EM>$menu</EM>-><STRONG>add</STRONG>(<EM>type, </EM>?<EM>option, value, option, value, ...</EM>?)</A></STRONG><BR>
- <DD>
- Add a new entry to the bottom of the menu. The new entry's type
- is given by <EM>type</EM> and must be one of <STRONG>cascade</STRONG>,
- <STRONG>checkbutton</STRONG>, <STRONG>command</STRONG>, <STRONG>radiobutton</STRONG>, or <STRONG>separator</STRONG>,
- or a unique abbreviation of one of the above. If additional arguments
- are present, they specify any of the following options:
- <DL>
- <DT><STRONG><A NAME="item_%2Dactivebackground_%3D%3E_value"><STRONG>-activebackground</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Specifies a background color to use for displaying this entry when it
- is active.
- If this option is specified as an empty string (the default), then the
- <STRONG>activeBackground</STRONG> option for the overall menu is used.
- If the <STRONG>$Tk::strictMotif</STRONG> variable has been set to request strict
- Motif compliance, then this option is ignored and the <STRONG>-background</STRONG>
- option is used in its place.
- This option is not available for separator or tear-off entries.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dactiveforeground_%3D%3E_value"><STRONG>-activeforeground</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Specifies a foreground color to use for displaying this entry when it
- is active.
- If this option is specified as an empty string (the default), then the
- <STRONG>activeForeground</STRONG> option for the overall menu is used.
- This option is not available for separator or tear-off entries.
- <P></P>
- <DT><STRONG><A NAME="item_%2Daccelerator_%3D%3E_value"><STRONG>-accelerator</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Specifies a string to display at the right side of the menu entry.
- Normally describes an accelerator keystroke sequence that may be
- typed to invoke the same function as the menu entry. This option
- is not available for separator or tear-off entries.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dbackground_%3D%3E_value"><STRONG>-background</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Specifies a background color to use for displaying this entry when it
- is in the normal state (neither active nor disabled).
- If this option is specified as an empty string (the default), then the
- <STRONG>background</STRONG> option for the overall menu is used.
- This option is not available for separator or tear-off entries.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dbitmap_%3D%3E_value"><STRONG>-bitmap</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Specifies a bitmap to display in the menu instead of a textual
- label, in any of the forms accepted by <STRONG>Tk_GetBitmap</STRONG>.
- This option overrides the <STRONG>-label</STRONG> option but may be reset
- to an empty string to enable a textual label to be displayed.
- If a <STRONG>-image</STRONG> option has been specified, it overrides
- <STRONG>-bitmap</STRONG>.
- This option is not available for separator or tear-off entries.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dcolumnbreak_%3D%3E_value"><STRONG>-columnbreak</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- When this option is zero, the appears below the previous entry. When
- this option is one, the menu appears at the top of a new column in the
- menu.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dcommand_%3D%3E_value"><STRONG>-command</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- For command, checkbutton, and radiobutton entries, specifies a
- callback to execute when the menu entry is invoked.
- For cascade entries, specifies a callback to execute
- when the entry is activated (i.e. just before its submenu is
- posted).
- Not available for separator or tear-off entries.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dfont_%3D%3E_value"><STRONG>-font</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Specifies the font to use when drawing the label or accelerator
- string in this entry.
- If this option is specified as an empty string (the default) then
- the <STRONG>font</STRONG> option for the overall menu is used.
- This option is not available for separator or tear-off entries.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dforeground_%3D%3E_value"><STRONG>-foreground</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Specifies a foreground color to use for displaying this entry when it
- is in the normal state (neither active nor disabled).
- If this option is specified as an empty string (the default), then the
- <STRONG>foreground</STRONG> option for the overall menu is used.
- This option is not available for separator or tear-off entries.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dhidemargin_%3D%3E_value"><STRONG>-hidemargin</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Specifies whether the standard margins should be drawn for this menu
- entry. This is useful when creating palette with images in them, i.e.,
- color palettes, pattern palettes, etc. 1 indicates that the margin for
- the entry is hidden; 0 means that the margin is used.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dimage_%3D%3E_value"><STRONG>-image</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Specifies an image to display in the menu instead of a text string
- or bitmap
- The image must have been created by some previous invocation of
- <STRONG>image create</STRONG>.
- This option overrides the <STRONG>-label</STRONG> and <STRONG>-bitmap</STRONG> options
- but may be reset to an empty string to enable a textual or
- bitmap label to be displayed.
- This option is not available for separator or tear-off entries.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dindicatoron_%3D%3E_value"><STRONG>-indicatoron</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Available only for checkbutton and radiobutton entries.
- <EM>Value</EM> is a boolean that determines whether or not the
- indicator should be displayed.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dlabel_%3D%3E_value"><STRONG>-label</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Specifies a string to display as an identifying label in the menu
- entry. Not available for separator or tear-off entries.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dmenu_%3D%3E_value"><STRONG>-menu</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Available only for cascade entries. Specifies the path name of
- the submenu associated with this entry.
- The submenu must be a child of the menu.
- <P></P>
- <DT><STRONG><A NAME="item_%2Doffvalue_%3D%3E_value"><STRONG>-offvalue</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Available only for checkbutton entries. Specifies the value to
- store in the entry's associated variable when the entry is
- deselected.
- <P></P>
- <DT><STRONG><A NAME="item_%2Donvalue_%3D%3E_value"><STRONG>-onvalue</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Available only for checkbutton entries. Specifies the value to
- store in the entry's associated variable when the entry is selected.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dselectcolor_%3D%3E_value"><STRONG>-selectcolor</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Available only for checkbutton and radiobutton entries.
- Specifies the color to display in the indicator when the entry is
- selected.
- If the value is an empty string (the default) then the <STRONG>selectColor</STRONG>
- option for the menu determines the indicator color.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dselectimage_%3D%3E_value"><STRONG>-selectimage</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Available only for checkbutton and radiobutton entries.
- Specifies an image to display in the entry (in place of
- the <STRONG>-image</STRONG> option) when it is selected.
- <EM>Value</EM> is the name of an image, which must have been created
- by some previous invocation of <STRONG>image create</STRONG>.
- This option is ignored unless the <STRONG>-image</STRONG> option has
- been specified.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dstate_%3D%3E_value"><STRONG>-state</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Specifies one of three states for the entry: <STRONG>normal</STRONG>, <STRONG>active</STRONG>,
- or <STRONG>disabled</STRONG>. In normal state the entry is displayed using the
- <STRONG>foreground</STRONG> option for the menu and the <STRONG>background</STRONG>
- option from the entry or the menu.
- The active state is typically used when the pointer is over the entry.
- In active state the entry is displayed using the <STRONG>activeForeground</STRONG>
- option for the menu along with the <STRONG>activebackground</STRONG> option from
- the entry. Disabled state means that the entry
- should be insensitive: the default bindings will refuse to activate
- or invoke the entry.
- In this state the entry is displayed according to the
- <STRONG>disabledForeground</STRONG> option for the menu and the
- <STRONG>background</STRONG> option from the entry.
- This option is not available for separator entries.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dunderline_%3D%3E_value"><STRONG>-underline</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Specifies the integer index of a character to underline in the entry.
- This option is also queried by the default bindings and used to
- implement keyboard traversal.
- 0 corresponds to the first character of the text displayed in the entry,
- 1 to the next character, and so on.
- If a bitmap or image is displayed in the entry then this option is ignored.
- This option is not available for separator or tear-off entries.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dvalue_%3D%3E_value"><STRONG>-value</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Available only for radiobutton entries. Specifies the value to
- store in the entry's associated variable when the entry is selected.
- If an empty string is specified, then the <STRONG>-label</STRONG> option
- for the entry as the value to store in the variable.
- <P></P>
- <DT><STRONG><A NAME="item_%2Dvariable_%3D%3E_value"><STRONG>-variable</STRONG> => <EM>value</EM></A></STRONG><BR>
- <DD>
- Available only for checkbutton and radiobutton entries. Specifies
- the name of a global value to set when the entry is selected.
- For checkbutton entries the variable is also set when the entry
- is deselected. For radiobutton entries, changing the variable
- causes the currently-selected entry to deselect itself.
- <P></P></DL>
- <P>The <STRONG>add</STRONG> method returns an empty string.</P>
- <DT><STRONG><A NAME="item_clone"><EM>$menu</EM>-><STRONG>clone</STRONG>(<EM>$parent</EM> ?, <EM>cloneType?</EM>)</A></STRONG><BR>
- <DD>
- Makes a clone of the current menu as a child of <EM>$parent</EM>. This clone
- is a menu in its own right, but any changes to the clone are
- propogated to the original menu and vice versa. <EM>cloneType</EM> can be
- <STRONG>normal</STRONG>, <STRONG>menubar</STRONG>, or <STRONG>tearoff</STRONG>. Should not normally be
- called outside of the Tk library. See <A HREF="#clones">CLONES</A> for
- more information.
- <P></P>
- <DT><STRONG><A NAME="item_delete"><EM>$menu</EM>-><STRONG>delete</STRONG>(<EM>index1</EM>?, <EM>index2</EM>?)</A></STRONG><BR>
- <DD>
- Delete all of the menu entries between <EM>index1</EM> and
- <EM>index2</EM> inclusive.
- If <EM>index2</EM> is omitted then it defaults to <EM>index1</EM>.
- Attempts to delete a tear-off menu entry are ignored (instead, you
- should change the <STRONG>tearOff</STRONG> option to remove the tear-off entry).
- <P></P>
- <DT><STRONG><A NAME="item_entrycget"><EM>$menu</EM>-><STRONG>entrycget</STRONG>(<EM>index, option</EM>)</A></STRONG><BR>
- <DD>
- Returns the current value of a configuration option for
- the entry given by <EM>index</EM>.
- <EM>Option</EM> may have any of the values accepted by the <STRONG>add</STRONG>
- method.
- <P></P>
- <DT><STRONG><A NAME="item_entryconfigure"><EM>$menu</EM>-><STRONG>entryconfigure</STRONG>(<EM>index</EM> ?,<EM>options</EM>?)</A></STRONG><BR>
- <DD>
- This method is similar to the <STRONG>configure</STRONG> method, except that
- it applies to the options for an individual entry, whereas <STRONG>configure</STRONG>
- applies to the options for the menu as a whole.
- <EM>Options</EM> may have any of the values accepted by the <STRONG>add</STRONG>
- method. If <EM>options</EM> are specified, options are modified
- as indicated
- in the method call and the method returns an empty string.
- If no <EM>options</EM> are specified, returns a list describing
- the current options for entry <EM>index</EM> (see <A HREF="../../../site/lib/Tk/options.html">the Tk::options manpage</A> for
- information on the format of this list).
- <P></P>
- <DT><STRONG><A NAME="item_index"><EM>$menu</EM>-><STRONG>index</STRONG>(<EM>index</EM>)</A></STRONG><BR>
- <DD>
- Returns the numerical index corresponding to <EM>index</EM>, or
- <STRONG>none</STRONG> if <EM>index</EM> was specified as <STRONG>none</STRONG>.
- <P></P>
- <DT><STRONG><A NAME="item_insert"><EM>$menu</EM>-><STRONG>insert</STRONG>(<EM>index, type</EM>?, <EM>-option</EM>=><EM>value</EM>, ...?)</A></STRONG><BR>
- <DD>
- Same as the <STRONG>add</STRONG> method except that it inserts the new
- entry just before the entry given by <EM>index</EM>, instead of appending
- to the end of the menu. The <EM>type</EM>, <EM>-option</EM>, and <EM>value</EM>
- arguments have the same interpretation as for the <STRONG>add</STRONG> widget
- method. It is not possible to insert new menu entries before the
- tear-off entry, if the menu has one.
- <P></P>
- <DT><STRONG><A NAME="item_invoke"><EM>$menu</EM>-><STRONG>invoke</STRONG>(<EM>index</EM>)</A></STRONG><BR>
- <DD>
- Invoke the action of the menu entry. See the sections on the
- individual entries above for details on what happens. If the
- menu entry is disabled then nothing happens. If the
- entry has a callback associated with it then the result of that
- callback is returned as the result of the <STRONG>invoke</STRONG> widget
- method. Otherwise the result is an empty string. Note: invoking
- a menu entry does not automatically unpost the menu; the default
- bindings normally take care of this before invoking the <STRONG>invoke</STRONG>
- method.
- <P></P>
- <DT><STRONG><A NAME="item_post"><EM>$menu</EM>-><STRONG>post</STRONG>(<EM>x, y</EM>)</A></STRONG><BR>
- <DD>
- Arrange for the menu to be displayed on the screen at the root-window
- coordinates given by <EM>x</EM> and <EM>y</EM>. These coordinates are
- adjusted if necessary to guarantee that the entire menu is visible on
- the screen. This method normally returns an empty string.
- If the <STRONG>postCommand</STRONG> option has been specified, then its value is
- executed before posting the menu and the result of
- that callback is returned as the result of the <STRONG>post</STRONG> widget
- method.
- If an error returns while executing the method, then the error is
- returned without posting the menu.
- <P></P>
- <DT><STRONG><A NAME="item_postcascade"><EM>$menu</EM>-><STRONG>postcascade</STRONG>(<EM>index</EM>)</A></STRONG><BR>
- <DD>
- Posts the submenu associated with the cascade entry given by
- <EM>index</EM>, and unposts any previously posted submenu.
- If <EM>index</EM> doesn't correspond to a cascade entry,
- or if <EM>$menu</EM> isn't posted,
- the method has no effect except to unpost any currently posted
- submenu.
- <P></P>
- <DT><STRONG><A NAME="item_type"><EM>$menu</EM>-><STRONG>type</STRONG>(<EM>index</EM>)</A></STRONG><BR>
- <DD>
- Returns the type of the menu entry given by <EM>index</EM>.
- This is the <EM>type</EM> argument passed to the <STRONG>add</STRONG> widget
- method when the entry was created, such as <STRONG>command</STRONG>
- or <STRONG>separator</STRONG>, or <STRONG>tearoff</STRONG> for a tear-off entry.
- <P></P>
- <DT><STRONG><A NAME="item_unpost"><EM>$menu</EM>-><STRONG>unpost</STRONG></A></STRONG><BR>
- <DD>
- Unmap the window so that it is no longer displayed. If a
- lower-level cascaded menu is posted, unpost that menu. Returns an
- empty string. This method does not work on Windows and the
- Macintosh, as those platforms have their own way of unposting menus.
- <P></P>
- <DT><STRONG><A NAME="item_yposition"><EM>$menu</EM>-><STRONG>yposition</STRONG>(<EM>index</EM>)</A></STRONG><BR>
- <DD>
- Returns a decimal string giving the y-coordinate within the menu
- window of the topmost pixel in the entry specified by <EM>index</EM>.
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="menu configurations">MENU CONFIGURATIONS</A></H1>
- <P>The default bindings support four different ways of using menus:</P>
- <DL>
- <DT><STRONG><A NAME="item_Pulldown_Menus_in_Menubar"><STRONG>Pulldown Menus in Menubar</STRONG></A></STRONG><BR>
- <DD>
- This is the most command case. You create a menu widget that will become the
- menu bar. You then add cascade entries to this menu, specifying the
- pull down menus you wish to use in your menu bar. You then create all
- of the pulldowns. Once you have done this, specify the menu using the
- <STRONG>-menu</STRONG> option of the toplevel's method. See the
- <STRONG>toplevel</STRONG> manual entry for details.
- <P></P>
- <DT><STRONG><A NAME="item_Pulldown_Menus_in_Menu_Buttons"><STRONG>Pulldown Menus in Menu Buttons</STRONG></A></STRONG><BR>
- <DD>
- This is the compatable way to do menu bars. You create one menubutton
- widget for each top-level menu, and typically you arrange a series of
- menubuttons in a row in a menubar window. You also create the top-level menus
- and any cascaded submenus, and tie them together with <STRONG>-menu</STRONG>
- options in menubuttons and cascade menu entries. The top-level menu must
- be a child of the menubutton, and each submenu must be a child of the
- menu that refers to it. Once you have done this, the default bindings
- will allow users to traverse and invoke the tree of menus via its
- menubutton; see the <STRONG>menubutton</STRONG> documentation for details.
- <P></P>
- <DT><STRONG><A NAME="item_Popup_Menus"><STRONG>Popup Menus</STRONG></A></STRONG><BR>
- <DD>
- Popup menus typically post in response to a mouse button press or
- keystroke. You create the popup menus and any cascaded submenus,
- then you call the <STRONG>Post</STRONG> method at the appropriate time
- to post the top-level menu.
- <P><EM>$menu</EM>-><STRONG>Post</STRONG>(<EM>$x</EM>,<EM>$y</EM>?,<EM>$entry</EM>?)</P>
- <P><EM>$x</EM> and <EM>$y</EM> are the root window coordinates at which the <EM>$menu</EM>
- will be displayed. If <EM>$entry</EM> is specified then that entry is centred
- on that point, otherwise the top-left corner of the <EM>$menu</EM> is placed
- at that point.</P>
- <P><STRONG>Menu</STRONG> also inherits methods from <A HREF="../../../site/lib/Tk/Wm.html">the Tk::Wm manpage</A> and so the method
- <STRONG>Popup</STRONG> can be used to position menu relative to other windows, the
- mouse cursor or the screen.</P>
- <P></P>
- <DT><STRONG><A NAME="item_Option_Menus"><STRONG>Option Menus</STRONG></A></STRONG><BR>
- <DD>
- An option menu consists of a menubutton with an associated menu
- that allows you to select one of several values. The current value
- is displayed in the menubutton and is also stored in a global
- variable. Use the <A HREF="../../../site/lib/Tk/Optionmenu.html">the Tk::Optionmenu manpage</A> class to create option
- menubuttons and their menus.
- <P></P>
- <DT><STRONG><A NAME="item_Torn%2Doff_Menus"><STRONG>Torn-off Menus</STRONG></A></STRONG><BR>
- <DD>
- You create a torn-off menu by invoking the tear-off entry at
- the top of an existing menu. The default bindings will create a new menu
- that is a copy of the original menu and leave it permanently
- posted as a top-level window. The torn-off menu behaves just
- the same as the original menu.
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="default bindings">DEFAULT BINDINGS</A></H1>
- <P>Tk automatically creates class bindings for menus that give them
- the following default behavior:</P>
- <DL>
- <DT><STRONG><A NAME="item_%5B1%5D">[1]</A></STRONG><BR>
- <DD>
- When the mouse enters a menu, the entry underneath the mouse
- cursor activates; as the mouse moves around the menu, the active
- entry changes to track the mouse.
- <P></P>
- <DT><STRONG><A NAME="item_%5B2%5D">[2]</A></STRONG><BR>
- <DD>
- When the mouse leaves a menu all of the entries in the menu
- deactivate, except in the special case where the mouse moves from
- a menu to a cascaded submenu.
- <P></P>
- <DT><STRONG><A NAME="item_%5B3%5D">[3]</A></STRONG><BR>
- <DD>
- When a button is released over a menu, the active entry (if any) is invoked.
- The menu also unposts unless it is a torn-off menu.
- <P></P>
- <DT><STRONG><A NAME="item_%5B4%5D">[4]</A></STRONG><BR>
- <DD>
- The Space and Return keys invoke the active entry and
- unpost the menu.
- <P></P>
- <DT><STRONG><A NAME="item_%5B5%5D">[5]</A></STRONG><BR>
- <DD>
- If any of the entries in a menu have letters underlined with
- with <STRONG>-underline</STRONG> option, then pressing one of the underlined
- letters (or its upper-case or lower-case equivalent) invokes that
- entry and unposts the menu.
- <P></P>
- <DT><STRONG><A NAME="item_%5B6%5D">[6]</A></STRONG><BR>
- <DD>
- The Escape key aborts a menu selection in progress without invoking any
- entry. It also unposts the menu unless it is a torn-off menu.
- <P></P>
- <DT><STRONG><A NAME="item_%5B7%5D">[7]</A></STRONG><BR>
- <DD>
- The Up and Down keys activate the next higher or lower entry
- in the menu. When one end of the menu is reached, the active
- entry wraps around to the other end.
- <P></P>
- <DT><STRONG><A NAME="item_%5B8%5D">[8]</A></STRONG><BR>
- <DD>
- The Left key moves to the next menu to the left.
- If the current menu is a cascaded submenu, then the submenu is
- unposted and the current menu entry becomes the cascade entry
- in the parent.
- If the current menu is a top-level menu posted from a
- menubutton, then the current menubutton is unposted and the
- next menubutton to the left is posted.
- Otherwise the key has no effect.
- The left-right order of menubuttons is determined by their stacking
- order: Tk assumes that the lowest menubutton (which by default
- is the first one created) is on the left.
- <P></P>
- <DT><STRONG><A NAME="item_%5B9%5D">[9]</A></STRONG><BR>
- <DD>
- The Right key moves to the next menu to the right.
- If the current entry is a cascade entry, then the submenu is
- posted and the current menu entry becomes the first entry
- in the submenu.
- Otherwise, if the current menu was posted from a
- menubutton, then the current menubutton is unposted and the
- next menubutton to the right is posted.
- <P>Disabled menu entries are non-responsive: they don't activate and
- they ignore mouse button presses and releases.</P>
- <P>The behavior of menus can be changed by defining new bindings for
- individual widgets or by redefining the class bindings.</P>
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="bugs">BUGS</A></H1>
- <P>At present it isn't possible to use the
- option database to specify values for the options to individual
- entries.</P>
- <P>
- <HR>
- <H1><A NAME="see also">SEE ALSO</A></H1>
- <P><A HREF="../../../site/lib/Tk/callbacks.html">Tk::callbacks</A></P>
- <P>
- <HR>
- <H1><A NAME="keywords">KEYWORDS</A></H1>
- <P>menu, widget</P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Tk::Menu - Create and manipulate Menu widgets</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-