| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 2 |
<html> |
| 3 |
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ --> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 6 |
<title>tk-menu-bar (GCL TK Manual)</title> |
| 7 |
|
| 8 |
<meta name="description" content="tk-menu-bar (GCL TK Manual)"> |
| 9 |
<meta name="keywords" content="tk-menu-bar (GCL TK Manual)"> |
| 10 |
<meta name="resource-type" content="document"> |
| 11 |
<meta name="distribution" content="global"> |
| 12 |
<meta name="Generator" content="makeinfo"> |
| 13 |
<link href="index.html" rel="start" title="Top"> |
| 14 |
<link href="wm.html#SEC_Contents" rel="contents" title="Table of Contents"> |
| 15 |
<link href="Control.html" rel="up" title="Control"> |
| 16 |
<link href="option.html" rel="next" title="option"> |
| 17 |
<link href="lower.html" rel="prev" title="lower"> |
| 18 |
<style type="text/css"> |
| 19 |
<!-- |
| 20 |
a.summary-letter {text-decoration: none} |
| 21 |
blockquote.indentedblock {margin-right: 0em} |
| 22 |
div.display {margin-left: 3.2em} |
| 23 |
div.example {margin-left: 3.2em} |
| 24 |
div.lisp {margin-left: 3.2em} |
| 25 |
kbd {font-style: oblique} |
| 26 |
pre.display {font-family: inherit} |
| 27 |
pre.format {font-family: inherit} |
| 28 |
pre.menu-comment {font-family: serif} |
| 29 |
pre.menu-preformatted {font-family: serif} |
| 30 |
span.nolinebreak {white-space: nowrap} |
| 31 |
span.roman {font-family: initial; font-weight: normal} |
| 32 |
span.sansserif {font-family: sans-serif; font-weight: normal} |
| 33 |
ul.no-bullet {list-style: none} |
| 34 |
--> |
| 35 |
</style> |
| 36 |
|
| 37 |
|
| 38 |
</head> |
| 39 |
|
| 40 |
<body lang="en"> |
| 41 |
<span id="tk_002dmenu_002dbar"></span><div class="header"> |
| 42 |
<p> |
| 43 |
Next: <a href="option.html" accesskey="n" rel="next">option</a>, Previous: <a href="lower.html" accesskey="p" rel="prev">lower</a>, Up: <a href="Control.html" accesskey="u" rel="up">Control</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 44 |
</div> |
| 45 |
<hr> |
| 46 |
<span id="tk_002dmenu_002dbar-1"></span><h3 class="section">3.10 tk-menu-bar</h3> |
| 47 |
|
| 48 |
<p>tk-menu-bar, tk_bindForTraversal \- Support for menu bars |
| 49 |
</p><span id="Synopsis-24"></span><h4 class="unnumberedsubsec">Synopsis</h4> |
| 50 |
<p><b>tk-menu-bar </b><i>frame </i><span class="roman">?</span><i>menu menu ...</i>? |
| 51 |
</p><br> |
| 52 |
<p><b>tk_bindForTraversal </b><i>arg arg ... </i> |
| 53 |
</p> |
| 54 |
<span id="Description-21"></span><h4 class="unnumberedsubsec">Description</h4> |
| 55 |
|
| 56 |
<p>These two commands are Tcl procedures in the Tk script library. |
| 57 |
They provide support for menu bars. |
| 58 |
A menu bar is a frame that contains a collection of menu buttons that |
| 59 |
work together, so that the user can scan from one menu to another with |
| 60 |
the mouse: if the mouse button is pressed over one menubutton (causing it |
| 61 |
to post its menu) and the mouse is moved over another menubutton |
| 62 |
in the same menu bar without releasing the mouse button, then the |
| 63 |
menu of the first menubutton is unposted and the menu of the |
| 64 |
new menubutton is posted instead. |
| 65 |
Menus in a menu bar can also be accessed using keyboard traversal (i.e. |
| 66 |
by typing keystrokes instead of using the mouse). |
| 67 |
In order for an application to use these procedures, it must do three |
| 68 |
things, which are described in the paragraphs below. |
| 69 |
</p> |
| 70 |
<p>First, each application must call <b>tk-menu-bar</b> to provide information |
| 71 |
about the menubar. |
| 72 |
The <i>frame</i> argument gives the path name of the frame that contains |
| 73 |
all of the menu buttons, and the <i>menu</i> arguments give path names |
| 74 |
for all of the menu buttons associated with the menu bar. |
| 75 |
Normally <i>frame</i><span class="roman"> is the parent of each of the </span><i>menu</i>’s. |
| 76 |
This need not be the case, but <i>frame</i> must be an ancestor of |
| 77 |
each of the <i>menu</i>’s in order for grabs to work correctly when |
| 78 |
the mouse is used to pull down menus. |
| 79 |
The order of the <i>menu</i> arguments determines the traversal order |
| 80 |
for the menu buttons. |
| 81 |
If <b>tk-menu-bar</b><span class="roman"> is called without any </span><i>menu</i> arguments, it |
| 82 |
returns a list containing the current menu buttons for <i>frame</i>, |
| 83 |
or an empty string if <i>frame</i> isn’t currently set up as a menu bar. |
| 84 |
If <b>tk-menu-bar</b><span class="roman"> is called with a single </span><i>menu</i> argument |
| 85 |
consisting of an empty string, any menubar information for <i>frame</i> |
| 86 |
is removed; from now on the menu buttons will function independently |
| 87 |
without keyboard traversal. |
| 88 |
Only one menu bar may be defined at a time within each top-level window. |
| 89 |
</p> |
| 90 |
<p>The second thing an application must do is to identify the traversal |
| 91 |
characters for menu buttons and menu entries. |
| 92 |
This is done by underlining those characters using the |
| 93 |
<b>:underline</b> options for the widgets. |
| 94 |
The menu traversal system uses this information to traverse the |
| 95 |
menus under keyboard control (see below). |
| 96 |
</p> |
| 97 |
<p>The third thing that an application must do |
| 98 |
is to make sure that the input focus is always in a window that |
| 99 |
has been configured to support menu traversal. |
| 100 |
If the input focus is <b>none</b> then input characters will |
| 101 |
be discarded and no menu traversal will be possible. |
| 102 |
If you have no other place to set the focus, set it to the menubar |
| 103 |
widget: <b>tk-menu-bar</b><span class="roman"> creates bindings for its </span><i>frame</i> argument to |
| 104 |
support menu traversal. |
| 105 |
</p> |
| 106 |
<p>The Tk startup scripts configure all the Tk widget classes with |
| 107 |
bindings to support menu traversal, so menu traversal will be possible |
| 108 |
regardless of which widget has the focus. |
| 109 |
If your application defines new classes of widgets that support the |
| 110 |
input focus, then you should call <b>tk_bindForTraversal</b> for |
| 111 |
each of these classes. |
| 112 |
<b>Tk_bindForTraversal</b> takes any number of arguments, each of |
| 113 |
which is a widget path name or widget class name. |
| 114 |
It sets up bindings for all the named widgets and |
| 115 |
classes so that the menu traversal system will be invoked when |
| 116 |
appropriate keystrokes are typed in those widgets or classes. |
| 117 |
</p> |
| 118 |
<span id="g_t_0022Menu-Traversal-Bindings_0022"></span><h4 class="unnumberedsubsec">"Menu Traversal Bindings"</h4> |
| 119 |
|
| 120 |
<p>Once an application has made the three arrangements described |
| 121 |
above, menu traversal will be available. |
| 122 |
At any given time, the only menus available for traversal |
| 123 |
are those associated with the top-level window containing the |
| 124 |
input focus. |
| 125 |
Menu traversal is initiated by one of the following actions: |
| 126 |
</p><ul class="no-bullet"> |
| 127 |
<li> [1] |
| 128 |
If <F10> is typed, then the first menu button in the list for the |
| 129 |
top-level window is posted and the first entry within that |
| 130 |
menu is selected. |
| 131 |
</li><li> [2] |
| 132 |
If <Alt-<i>key</i><span class="roman">> is pressed, then the menu button that has </span><i>key</i> |
| 133 |
as its underlined character is posted |
| 134 |
and the first entry within that menu is selected. |
| 135 |
The comparison between <i>key</i> and the underlined characters |
| 136 |
ignores case differences. |
| 137 |
If no menu button matches <i>key</i> then the keystroke has no |
| 138 |
effect. |
| 139 |
</li><li> [3] |
| 140 |
Clicking mouse button 1 on a menu button posts that menu and selects |
| 141 |
its first entry. |
| 142 |
</li></ul> |
| 143 |
|
| 144 |
|
| 145 |
<p>Once a menu has been posted, the input focus is switched to that |
| 146 |
menu and the following actions are possible: |
| 147 |
</p><ul class="no-bullet"> |
| 148 |
<li> [1] |
| 149 |
Typing <ESC> or clicking mouse button 1 outside the menu button or |
| 150 |
its menu will abort the menu traversal. |
| 151 |
</li><li> [2] |
| 152 |
If <Alt-<i>key</i>> is pressed, then the entry in the posted menu |
| 153 |
whose underlined character is <i>key</i> is invoked. |
| 154 |
This causes the menu to be unposted, the entry’s action to be |
| 155 |
taken, and the menu traversal to end. |
| 156 |
The comparison between <i>key</i> and underlined characters ignores |
| 157 |
case differences. |
| 158 |
If no menu entry matches <i>key</i> then the keystroke is ignored. |
| 159 |
</li><li> [3] |
| 160 |
The arrow keys may be used to move among entries and menus. |
| 161 |
The left and right arrow keys move circularly among the available |
| 162 |
menus and the up and down arrow keys move circularly among the |
| 163 |
entries in the current menu. |
| 164 |
</li><li> [4] |
| 165 |
If <Return> is pressed, the selected entry in the posted menu is |
| 166 |
invoked, which causes the menu to be unposted, the entry’s action |
| 167 |
to be taken, and the menu traversal to end. |
| 168 |
</li></ul> |
| 169 |
|
| 170 |
<p>When a menu traversal completes, the input focus reverts to the |
| 171 |
window that contained it when the traversal started. |
| 172 |
</p> |
| 173 |
<span id="Keywords-24"></span><h4 class="unnumberedsubsec">Keywords</h4> |
| 174 |
<p>keyboard traversal, menu, menu bar, post |
| 175 |
</p><hr> |
| 176 |
<div class="header"> |
| 177 |
<p> |
| 178 |
Next: <a href="option.html" accesskey="n" rel="next">option</a>, Previous: <a href="lower.html" accesskey="p" rel="prev">lower</a>, Up: <a href="Control.html" accesskey="u" rel="up">Control</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 179 |
</div> |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
</body> |
| 184 |
</html> |