stk/Help/menubutton.n.html

242 lines
12 KiB
HTML

<HTML><HEAD><TITLE>Tk Built-In Commands - menubutton manual page</TITLE></HEAD>
<BR>
<BODY bgcolor = #c3c3ff>
<H2><IMG ALIGN=BOTTOM SRC="./Img/ManPageBlue.gif"> menubutton</H2>
<I>Create and manipulate menubutton widgets</I><P><IMG ALIGN=TOP SRC="./Img/line-red.gif">
<H3><A NAME="M2">SYNOPSIS</A></H3>
(<B>menubutton</B><I> widget-name </I>?<I>options</I>?)<BR>
<H3><A NAME="M3">STANDARD OPTIONS</A></H3>
<PRE>
<B><A HREF="options.n.html#M:activebackground">:activebackground</A></B> <B><A HREF="options.n.html#M:activeforeground">:activeforeground</A></B>
<B><A HREF="options.n.html#M:anchor">:anchor</A></B> <B><A HREF="options.n.html#M:background">:background</A></B>
<B><A HREF="options.n.html#M:bitmap">:bitmap</A></B> <B><A HREF="options.n.html#M:borderwidth">:borderwidth</A></B>
<B><A HREF="options.n.html#M:cursor">:cursor</A></B> <B><A HREF="options.n.html#M:disabledforeground">:disabledforeground</A></B>
<B><A HREF="options.n.html#M:font">:font</A></B> <B><A HREF="options.n.html#M:foreground">:foreground</A></B>
<B><A HREF="options.n.html#M:highlightbackground">:highlightbackground</A></B> <B><A HREF="options.n.html#M:highlightcolor">:highlightcolor</A></B>
<B><A HREF="options.n.html#M:highlightthickness">:highlightthickness</A></B> <B><A HREF="options.n.html#M:image">:image</A></B>
<B><A HREF="options.n.html#M:justify">:justify</A></B> <B><A HREF="options.n.html#M:padx">:padx</A></B>
<B><A HREF="options.n.html#M:pady">:pady</A></B> <B><A HREF="options.n.html#M:relief">:relief</A></B>
<B><A HREF="options.n.html#M:takefocus">:takefocus</A></B> <B><A HREF="options.n.html#M:text">:text</A></B>
<B><A HREF="options.n.html#M:textvariable">:textvariable</A></B> <B><A HREF="options.n.html#M:underline">:underline</A></B>
<B><A HREF="options.n.html#M:wraplength">:wraplength</A></B>
</PRE>
<H3><A NAME="M27">WIDGET-SPECIFIC OPTIONS</A></H3>
<DL>
<P>
<DT><I>Name</I>: <B>direction</B>
<DT><I>Class</I>: <B>Height</B>
<DT><I>Option keyword</I>: <B><A NAME="M28">:direction</A></B>
<DT><I>STklos slot name</I>: <B>direction</B>
<DD>Specifies where the menu is going to be popup up. <B>above</B> tries to
pop the menu above the menubutton. <B>below</B> tries to pop the menu
below the menubutton. <B>left</B> tries to pop the menu to the left of
the menubutton. <B>right</B> tries to pop the menu to the right of the
menu button. <B>flush</B> pops the menu directly over the menubutton.
<P>
<P>
<DT><I>Name</I>: <B>environment</B>
<DT><I>Class</I>: <B>Environment</B>
<DT><I>Option keyword</I>: <B><A NAME="M29">:environment</A></B>
<DT><I>STklos slot name</I>: <B>environment</B>
<DD>Specifies the environment in which the <B>:textvariable</B> must be taken.
By default, the value of this option is the STk global environment.
<P>
<P>
<DT><I>Name</I>: <B>height</B>
<DT><I>Class</I>: <B>Height</B>
<DT><I>Option keyword</I>: <B><A NAME="M30">:height</A></B>
<DT><I>STklos slot name</I>: <B>height</B>
<DD>Specifies a desired height for the menubutton.
If an image or bitmap is being displayed in the menubutton then the value is in
screen units (i.e. any of the forms acceptable to <B>Tk_GetPixels</B>);
for text it is in lines of text.
If this option isn't specified, the menubutton's desired height is computed
from the size of the image or bitmap or text being displayed in it.
<P>
<P>
<DT><I>Name</I>: <B>indicatorOn</B>
<DT><I>Class</I>: <B>IndicatorOn</B>
<DT><I>Option keyword</I>: <B><A NAME="M31">:indicatoron</A></B>
<DT><I>STklos slot name</I>: <B>indicator-on</B>
<DD>The value must be a proper boolean value. If it is true then
a small indicator rectangle will be displayed on the right side
of the menubutton and the default menu bindings will treat this
as an option menubutton. If false then no indicator will be
displayed.
<P>
<P>
<DT><I>Name</I>: <B><A HREF="./menu.n.html">menu</A></B>
<DT><I>Class</I>: <B>MenuName</B>
<DT><I>Option keyword</I>: <B><A NAME="M32">:menu</A></B>
<DT><I>STklos slot name</I>: <B>menu-name</B>
<DD>Specifies the path name of the menu associated with this menubutton.
The menu must be a child of the menubutton.
<P>
<P>
<DT><I>Name</I>: <B>state</B>
<DT><I>Class</I>: <B>State</B>
<DT><I>Option keyword</I>: <B><A NAME="M33">:state</A></B>
<DT><I>STklos slot name</I>: <B>state</B>
<DD>Specifies one of three states for the menubutton: <B>normal</B>, <B>active</B>,
or <B>disabled</B>. In normal state the menubutton is displayed using the
<B>foreground</B> and <B>background</B> options. The active state is
typically used when the pointer is over the menubutton. In active state
the menubutton is displayed using the <B>activeForeground</B> and
<B>activeBackground</B> options. Disabled state means that the menubutton
should be insensitive: the default bindings will refuse to activate
the widget and will ignore mouse button presses.
In this state the <B>disabledForeground</B> and
<B>background</B> options determine how the button is displayed.
<P>
<P>
<DT><I>Name</I>: <B>width</B>
<DT><I>Class</I>: <B>Width</B>
<DT><I>Option keyword</I>: <B><A NAME="M34">:width</A></B>
<DT><I>STklos slot name</I>: <B>width</B>
<DD>Specifies a desired width for the menubutton.
If an image or bitmap is being displayed in the menubutton then the value is in
screen units (i.e. any of the forms acceptable to <B>Tk_GetPixels</B>);
for text it is in characters.
If this option isn't specified, the menubutton's desired width is computed
from the size of the image or bitmap or text being displayed in it.
<P>
</DL>
<H3><A NAME="M35">INTRODUCTION</A></H3>
The <B>menubutton</B> command creates a new window (given by the
<I>widget-name</I> argument) and makes it into a menubutton widget.
Additional
options, described above, may be specified on the command line
or in the option database
to configure aspects of the menubutton such as its colors, font,
text, and initial relief. The <B>menubutton</B> command returns its
<I>widget-name</I> argument. At the time this command is invoked,
there must not exist a window named <I>widget-name</I>, but
<I>widget-name</I>'s parent must exist.
<P>
A menubutton is a widget that displays a
textual string, bitmap, or image
and is associated with a menu widget.
If text is displayed, it must all be in a single font, but it
can occupy multiple lines on the screen (if it contains newlines
or if wrapping occurs because of the <B>wrapLength</B> option) and
one of the characters may optionally be underlined using the
<B>underline</B> option.
In normal usage, pressing
mouse button 1 over the menubutton causes the associated menu to
be posted just underneath the menubutton. If the mouse is moved over
the menu before releasing the mouse button, the button release
causes the underlying menu entry to be invoked. When the button
is released, the menu is unposted.
<P>
Menubuttons are typically organized into groups called menu bars
that allow scanning:
if the mouse button is pressed over one menubutton (causing it
to post its menu) and the mouse is moved over another menubutton
in the same menu bar without releasing the mouse button, then the
menu of the first menubutton is unposted and the menu of the
new menubutton is posted instead.
<P>
There are several interactions between menubuttons and menus; see
the <B><A HREF="./menu.n.html">menu</A></B> manual entry for information on various menu configurations,
such as pulldown menus and option menus.
<H3><A NAME="M36">WIDGET COMMAND</A></H3>
The <B>menubutton</B> command creates a new STk command whose
name is <I>widget-name</I>. This
command may be used to invoke various
operations on the widget. It has the following general form:
<PRE>(<I>widget-name option </I>?<I>arg arg ...</I>?)</PRE>
<I>Option</I> and the <I>arg</I>s
determine the exact behavior of the command. The following
commands are possible for menubutton widgets:
<P>
<DL>
<DT><A NAME="M37">(<I>widget-name '</I><B>cget</B> <I>option</I>)</A><DD>
Returns the current value of the configuration option given
by <I>option</I>.
<I>Option</I> may have any of the values accepted by the <B>menubutton</B>
command.
<P>
<DT><A NAME="M38">(<I>widget-name '</I><B>configure</B> ?<I>option</I>? ?<I>value option value ...</I>?)</A><DD>
Query or modify the configuration options of the widget.
If no <I>option</I> is specified, returns a list describing all of
the available options for <I>widget-name</I> (see <B>Tk_ConfigureInfo</B> for
information on the format of this list). If <I>option</I> is specified
with no <I>value</I>, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no <I>option</I> is specified). If
one or more <I>option-value</I> pairs are specified, then the command
modifies the given widget option(s) to have the given value(s); in
this case the command returns an empty string.
<I>Option</I> may have any of the values accepted by the <B>menubutton</B>
command.
<P>
</DL>
<H3><A NAME="M39">DEFAULT BINDINGS</A></H3>
Tk automatically creates class bindings for menubuttons that give them
the following default behavior:
<P>
<DL>
<DT><A NAME="M40">{[1]}</A><DD>
A menubutton activates whenever the mouse passes over it and deactivates
whenever the mouse leaves it.
<P>
<DT><A NAME="M41">{[2]}</A><DD>
Pressing mouse button 1 over a menubutton posts the menubutton:
its relief changes to raised and its associated menu is posted
under the menubutton. If the mouse is dragged down into the menu
with the button still down, and if the mouse button is then
released over an entry in the menu, the menubutton is unposted
and the menu entry is invoked.
<P>
<DT><A NAME="M42">{[3]}</A><DD>
If button 1 is pressed over a menubutton and then released over that
menubutton, the menubutton stays posted: you can still move the mouse
over the menu and click button 1 on an entry to invoke it.
Once a menu entry has been invoked, the menubutton unposts itself.
<P>
<DT><A NAME="M43">{[4]}</A><DD>
If button 1 is pressed over a menubutton and then dragged over some
other menubutton, the original menubutton unposts itself and the
new menubutton posts.
<P>
<DT><A NAME="M44">{[5]}</A><DD>
If button 1 is pressed over a menubutton and released outside
any menubutton or menu, the menubutton unposts without invoking
any menu entry.
<P>
<DT><A NAME="M45">{[6]}</A><DD>
When a menubutton is posted, its associated menu claims the input
focus to allow keyboard traversal of the menu and its submenus.
See the <B><A HREF="./menu.n.html">menu</A></B> manual entry for details on these bindings.
<P>
<DT><A NAME="M46">{[7]}</A><DD>
If the <B>underline</B> option has been specified for a menubutton
then keyboard traversal may be used to post the menubutton:
Alt+<I>x</I>, where <I>x</I> is the underlined character (or its
lower-case or upper-case equivalent), may be typed in any window
under the menubutton's toplevel to post the menubutton.
<P>
<DT><A NAME="M47">{[8]}</A><DD>
The F10 key may be typed in any window to post the first menubutton
under its toplevel window that isn't disabled.
<P>
<DT><A NAME="M48">{[9]}</A><DD>
If a menubutton has the input focus, the space and return keys
post the menubutton.
<P>
</DL>
<P>
If the menubutton's state is <B>disabled</B> then none of the above
actions occur: the menubutton is completely non-responsive.
<P>
The behavior of menubuttons can be changed by defining new bindings for
individual widgets or by redefining the class bindings.
<H3><A NAME="M49">SEE ALSO</A></H3>
<B>menu option-menu</B>
<P><IMG ALIGN=TOP SRC="./Img/line-red.gif"><P>
<A HREF=./STk-hlp.html><IMG ALIGN=BOTTOM SRC="./Img/RefBookBlue.gif"> Back to the <B>STk</B> main page</A>
</BODY></HTML>