home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / tk3.3b1 / doc / menu.n < prev    next >
Encoding:
Text File  |  1993-04-01  |  19.8 KB  |  508 lines

  1. '\"
  2. '\" Copyright (c) 1990-1992 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/wish/man/RCS/menu.n,v 1.16 93/04/01 09:52:44 ouster Exp $ SPRITE (Berkeley)
  22. '/" 
  23. .so man.macros
  24. .HS menu tk
  25. .BS
  26. '\" Note:  do not modify the .SH NAME line immediately below!
  27. .SH NAME
  28. menu \- Create and manipulate menu widgets
  29. .SH SYNOPSIS
  30. \fBmenu\fI \fIpathName \fR?\fIoptions\fR?
  31. .SH "STANDARD OPTIONS"
  32. .LP
  33. .nf
  34. .ta 4c 8c 12c
  35. .VS
  36. \fBactiveBackground\fR    \fBbackground\fR    \fBdisabledForeground\fR
  37. \fBactiveBorderWidth\fR    \fBborderWidth\fR    \fBfont\fR
  38. \fBactiveForeground\fR    \fBcursor\fR    \fBforeground\fR
  39. .VE
  40. .fi
  41. .LP
  42. See the ``options'' manual entry for details on the standard options.
  43. .SH "WIDGET-SPECIFIC OPTIONS"
  44. .ta 4c
  45. .LP
  46. .nf
  47. Name:    \fBpostCommand\fR
  48. .VS
  49. Class:    \fBCommand\fR
  50. Command-Line Switch:    \fB\-postcommand\fR
  51. .fi
  52. .IP
  53. If this option is specified then it provides a Tcl command to execute
  54. each time the menu is posted.  The command is invoked by the \fBpost\fR
  55. widget command before posting the menu.
  56. .VE
  57. .LP
  58. .nf
  59. Name:    \fBselector\fR
  60. Class:    \fBForeground\fR
  61. Command-Line Switch:    \fB\-selector\fR
  62. .fi
  63. .IP
  64. For menu entries that are check buttons or radio buttons, this option
  65. specifies the color to display in the selector when the check button
  66. or radio button is selected.
  67. .BE
  68.  
  69. .SH INTRODUCTION
  70. .PP
  71. The \fBmenu\fR command creates a new top-level window (given
  72. by the \fIpathName\fR argument) and makes it into a menu widget.
  73. Additional
  74. options, described above, may be specified on the command line
  75. or in the option database
  76. to configure aspects of the menu such as its colors and font.
  77. The \fBmenu\fR command returns its
  78. \fIpathName\fR argument.  At the time this command is invoked,
  79. there must not exist a window named \fIpathName\fR, but
  80. \fIpathName\fR's parent must exist.
  81. .PP
  82. A menu is a widget that displays a collection of one-line entries arranged
  83. in a column.  There exist several different types of entries,
  84. each with different properties.  Entries of different types may be
  85. combined in a single menu.  Menu entries are not the same as
  86. entry widgets.  In fact, menu entries are not even distinct widgets;
  87. the entire menu is one widget.
  88. .PP
  89. Menu entries are displayed with up to three
  90. separate fields.  The main field is a label in the form of text or
  91. a bitmap, which is determined by the \fB\-label\fR or \fB\-bitmap\fR
  92. option for the entry.
  93. If the  \fB\-accelerator\fR option is specified for an entry then a second
  94. textual field is displayed to the right of the label.  The accelerator
  95. typically describes a keystroke sequence that may be typed in the
  96. application to cause the same result as invoking the menu entry.
  97. The third field is a \fIselector\fR.  The selector is present only for
  98. check-button or radio-button entries.  It indicates whether the entry
  99. is selected or not, and is displayed to the left of the entry's
  100. string.
  101. .PP
  102. In normal use, an entry becomes active (displays itself differently)
  103. whenever the mouse pointer is over the entry.  If a mouse
  104. button is released over the entry then the entry is \fIinvoked\fR.
  105. The effect of invocation is different for each type of entry;
  106. these effects are described below in the sections on individual
  107. entries.
  108. .PP
  109. Entries may be \fIdisabled\fR, which causes their labels
  110. and accelerators to be displayed
  111. with dimmer colors.  A disabled entry cannot be activated or invoked.
  112. Disabled entries may be re-enabled, at which point it becomes
  113. possible to activate and invoke them again.
  114.  
  115. .SH "COMMAND ENTRIES"
  116. .PP
  117. The most common kind of menu entry is a command entry, which
  118. behaves much like a button widget.  When a command entry is
  119. invoked, a Tcl command is executed.  The Tcl
  120. command is specified with the \fB\-command\fR option.
  121.  
  122. .SH "SEPARATOR ENTRIES"
  123. .PP
  124. A separator is an entry that is displayed as a horizontal dividing
  125. line.  A separator may not be activated or invoked, and it has
  126. no behavior other than its display appearance.
  127.  
  128. .SH "CHECK-BUTTON ENTRIES"
  129. .PP
  130. A check-button menu entry behaves much like a check-button widget.
  131. When it is invoked it toggles back and forth between the selected
  132. and deselected states.  When the entry is selected, a particular
  133. value is stored in a particular global variable (as determined by
  134. the \fB\-onvalue\fR and \fB\-variable\fR options for the entry);  when
  135. the entry is deselected another value (determined by the
  136. \fB\-offvalue\fR option) is stored in the global variable.
  137. A selector box is displayed to the left of the label in a check-button
  138. entry.  If the entry is selected then the box's center is displayed
  139. in the color given by the \fBselector\fR option for the menu;
  140. otherwise the box's center is displayed in the background color for
  141. the menu.  If a \fB\-command\fR option is specified for a check-button
  142. entry, then its value is evaluated as a Tcl command each time the entry
  143. is invoked;  this happens after toggling the entry's
  144. selected state.
  145.  
  146. .SH "RADIO-BUTTON ENTRIES"
  147. .PP
  148. A radio-button menu entry behaves much like a radio-button widget.
  149. Radio-button entries are organized in groups of which only one
  150. entry may be selected at a time.  Whenever a particular entry
  151. becomes selected it stores a particular value into a particular
  152. global variable (as determined by the \fB\-value\fR and
  153. \fB\-variable\fR options for the entry).  This action
  154. causes any previously-selected entry in the same group
  155. to deselect itself.
  156. Once an entry has become selected, any change to the entry's
  157. associated variable will cause the entry to deselect itself.
  158. Grouping of radio-button entries is determined by their
  159. associated variables:  if two entries have the same associated
  160. variable then they are in the same group.
  161. A selector diamond is displayed to the left of the label in each
  162. radio-button entry.  If the entry is selected then the diamond's
  163. center is displayed in the color given by the \fBselector\fR option
  164. for the menu;
  165. otherwise the diamond's center is displayed in the background color for
  166. the menu.  If a \fB\-command\fR option is specified for a radio-button
  167. entry, then its value is evaluated as a Tcl command each time the entry
  168. is invoked;  this happens after selecting the entry.
  169.  
  170. .SH "CASCADE ENTRIES"
  171. .PP
  172. A cascade entry is one with an associated menu (determined
  173. by the \fB\-menu\fR option.  Cascade entries allow the construction
  174. of cascading menus.  When the entry is activated, the
  175. associated menu is posted just to the right of the entry;
  176. that menu remains posted until the higher-level menu is unposted or
  177. until some other entry is activated in the higher-level menu.
  178. A cascade entry posts its associated menu by invoking a
  179. Tcl command of the form
  180. .RS
  181. .IP
  182. \fImenu\fB post \fIx y\fR
  183. .RE
  184. .LP
  185. where \fImenu\fR is the path name of the associated menu, \fIx\fR
  186. and \fIy\fR are the root-window coordinates of the upper-right
  187. corner of the cascade entry, and \fIgroup\fR is the name of the
  188. menu's group (as determined in its last \fBpost\fR widget command).
  189. The lower-level menu is unposted by executing a Tcl command with
  190. the form
  191. .RS
  192. .IP
  193. \fImenu\fB unpost\fR
  194. .RE
  195. .LP
  196. where \fImenu\fR is the name of the associated menu.
  197. .LP
  198. If a \fB\-command\fR option is specified for a cascade entry then it is
  199. .VS
  200. evaluated as a Tcl command each time the associated menu is posted (the
  201. evaluation occurs before the menu is posted).
  202. .VE
  203.  
  204. .SH "WIDGET COMMAND"
  205. .PP
  206. The \fBmenu\fR command creates a new Tcl command whose
  207. name is \fIpathName\fR.  This
  208. command may be used to invoke various
  209. operations on the widget.  It has the following general form:
  210. .DS C
  211. \fIpathName option \fR?\fIarg arg ...\fR?
  212. .DE
  213. \fIOption\fR and the \fIarg\fRs
  214. determine the exact behavior of the command.
  215. .PP
  216. Many of the widget commands for a menu take as one argument an
  217. indicator of which entry of the menu to operate on.  These
  218. indicators are called \fIindex\fRes and may be specified in
  219. any of the following forms:
  220. .TP 12
  221. \fInumber\fR
  222. Specifies the entry numerically, where 0 corresponds
  223. to the top-most entry of the menu, 1 to the entry below it, and
  224. so on.
  225. .TP 12
  226. \fBactive\fR
  227. Indicates the entry that is currently active.  If no entry is
  228. active then this form is equivalent to \fBnone\fR.  This form may
  229. not be abbreviated.
  230. .TP 12
  231. \fBlast\fR
  232. Indicates the bottommost entry in the menu.  If there are no
  233. entries in the menu then this form is equivalent to \fBnone\fR.
  234. This form may not be abbreviated.
  235. .TP 12
  236. \fBnone\fR
  237. Indicates ``no entry at all'';  this is used most commonly with
  238. the \fBactivate\fR option to deactivate all the entries in the
  239. menu.  In most cases the specification of \fBnone\fR causes
  240. nothing to happen in the widget command.
  241. This form may not be abbreviated.
  242. .TP 12
  243. \fB@\fInumber\fR
  244. In this form, \fInumber\fR is treated as a y-coordinate in the
  245. menu's window;  the entry spanning that y-coordinate is used.
  246. For example, ``\fB@0\fR'' indicates the top-most entry in the
  247. window.  If \fInumber\fR is outside the range of the window
  248. then this form is equivalent to \fBnone\fR.
  249. .TP 12
  250. \fIpattern\fR
  251. If the index doesn't satisfy one of the above forms then this
  252. form is used.  \fIPattern\fR is pattern-matched against the label of
  253. each entry in the menu, in order from the top down, until a
  254. matching entry is found.  The rules of \fBTcl_StringMatch\fR
  255. are used.
  256. .PP
  257. The following widget commands are possible for menu widgets:
  258. .TP
  259. \fIpathName \fBactivate \fIindex\fR
  260. Change the state of the entry indicated by \fIindex\fR to \fBactive\fR
  261. and redisplay it using its active colors.
  262. Any previously-active entry is deactivated.  If \fIindex\fR
  263. is specified as \fBnone\fR, or if the specified entry is
  264. disabled, then the menu ends up with no active entry.
  265. Returns an empty string.
  266. .TP
  267. \fIpathName \fBadd \fItype \fR?\fIoption value option value ...\fR?
  268. Add a new entry to the bottom of the menu.  The new entry's type
  269. is given by \fItype\fR and must be one of \fBcascade\fR,
  270. \fBcheckbutton\fR, \fBcommand\fR, \fBradiobutton\fR, or \fBseparator\fR,
  271. or a unique abbreviation of one of the above.  If additional arguments
  272. are present, they specify any of the following options:
  273. .RS
  274. .TP
  275. \fB\-activebackground \fIvalue\fR
  276. .VS
  277. Specifies a background color to use for displaying this entry when it
  278. is active.
  279. If this option is specified as an empty string (the default), then the
  280. \fBactiveBackground\fR option for the overall menu is used.
  281. This option is not available for separator entries.
  282. .VE
  283. .TP
  284. \fB\-accelerator \fIvalue\fR
  285. Specifies a string to display at the right side of the menu entry.
  286. Normally describes an accelerator keystroke sequence that may be
  287. typed to invoke the same function as the menu entry.  This option
  288. is not available for separator entries.
  289. .TP
  290. \fB\-background \fIvalue\fR
  291. .VS
  292. Specifies a background color to use for displaying this entry when it
  293. is in the normal state (neither active nor disabled).
  294. If this option is specified as an empty string (the default), then the
  295. \fBbackground\fR option for the overall menu is used.
  296. This option is not available for separator entries.
  297. .VE
  298. .TP
  299. \fB\-bitmap \fIvalue\fR
  300. Specifies a bitmap to display in the menu instead of a textual
  301. label, in any of the forms accepted by \fBTk_GetBitmap\fR.
  302. This option overrides the \fB\-label\fR option but may be reset
  303. to an empty string to enable a textual label to be displayed.
  304. This option is not available for separator entries.
  305. .TP
  306. \fB\-command \fIvalue\fR
  307. For command, checkbutton, and radiobutton entries, specifies a
  308. .VS
  309. Tcl command to execute when the menu entry is invoked.
  310. For cascade entries, specifies a Tcl command to execute
  311. when the entry is activated (i.e. just before its submenu is
  312. posted).
  313. .VE
  314. Not available for separator entries.
  315. .TP
  316. \fB\-font \fIvalue\fR
  317. .VS
  318. Specifies the font to use when drawing the label or accelerator
  319. string in this entry.
  320. If this option is specified as an empty string (the default) then
  321. the \fBfont\fR option for the overall menu is used.
  322. This option is not available for separator entries.
  323. .VE
  324. .TP
  325. \fB\-label \fIvalue\fR
  326. Specifies a string to display as an identifying label in the menu
  327. entry.  Not available for separator entries.
  328. .TP
  329. \fB\-menu \fIvalue\fR
  330. Available only for cascade entries.  Specifies the path name of
  331. the menu associated with this entry.
  332. .TP
  333. \fB\-offvalue \fIvalue\fR
  334. Available only for check-button entries.  Specifies the value to
  335. store in the entry's associated variable when the entry is
  336. deselected.
  337. .TP
  338. \fB\-onvalue \fIvalue\fR
  339. Available only for check-button entries.  Specifies the value to
  340. store in the entry's associated variable when the entry is selected.
  341. .TP
  342. \fB\-state \fIvalue\fR
  343. .VS
  344. Specifies one of three states for the entry:  \fBnormal\fR, \fBactive\fR,
  345. or \fBdisabled\fR.  In normal state the entry is displayed using the
  346. \fBforeground\fR option for the menu and the \fBbackground\fR
  347. option from the entry or the menu.
  348. The active state is typically used when the pointer is over the entry.
  349. In active state the entry is displayed using the \fBactiveForeground\fR
  350. option for the menu along with the \fBactivebackground\fR option from
  351. the entry.
  352. Disabled state means that the entry is insensitive:  it doesn't activate
  353. and doesn't respond to mouse button presses or releases.
  354. In this state the entry is displayed according to the 
  355. \fBdisabledForeground\fR option for the menu and the
  356. \fBbackground\fR option from the entry.
  357. This option is not available for separator entries.
  358. .TP
  359. \fB\-underline \fIvalue\fR
  360. Specifies the integer index of a character to underline in the entry.
  361. This option is typically used to indicate keyboard traversal characters.
  362. 0 corresponds to the first character of the text displayed in the entry,
  363. 1 to the next character, and so on.
  364. If a bitmap is displayed in the entry then this option is ignored.
  365. This option is not available for separator entries.
  366. .VE
  367. .TP
  368. \fB\-value \fIvalue\fR
  369. Available only for radio-button entries.  Specifies the value to
  370. store in the entry's associated variable when the entry is selected.
  371. .TP
  372. \fB\-variable \fIvalue\fR
  373. Available only for check-button and radio-button entries.  Specifies
  374. the name of a global value to set when the entry is selected.
  375. For check-button entries the variable is also set when the entry
  376. is deselected.  For radio-button entries, changing the variable
  377. causes the currently-selected entry to deselect itself.
  378. .LP
  379. The \fBadd\fR widget command returns an empty string.
  380. .RE
  381. .TP
  382. \fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
  383. Query or modify the configuration options of the widget.
  384. If no \fIoption\fR is specified, returns a list describing all of
  385. the available options for \fIpathName\fR (see \fBTk_ConfigureInfo\fR for
  386. information on the format of this list).  If \fIoption\fR is specified
  387. with no \fIvalue\fR, then the command returns a list describing the
  388. one named option (this list will be identical to the corresponding
  389. sublist of the value returned if no \fIoption\fR is specified).  If
  390. one or more \fIoption\-value\fR pairs are specified, then the command
  391. modifies the given widget option(s) to have the given value(s);  in
  392. this case the command returns an empty string.
  393. \fIOption\fR may have any of the values accepted by the \fBmenu\fR
  394. command.
  395. .TP
  396. \fIpathName \fBdelete \fIindex1\fR ?\fIindex2\fR?
  397. Delete all of the menu entries between \fIindex1\fR and
  398. .VS
  399. \fIindex2\fR inclusive.
  400. If \fIindex2\fR is omitted then it defaults to \fIindex1\fR.
  401. .VE
  402. Returns an empty string.
  403. .TP
  404. \fIpathName \fBdisable \fIindex\fR
  405. .VS
  406. Change the state of the entry given by \fIindex\fR to \fBdisabled\fR
  407. and redisplay the entry using its disabled colors.
  408. Returns an empty string.
  409. This command is obsolete and will eventually be removed;
  410. use ``\fIpathName \fBentryconfigure \fIindex\fR \-state disabled\fR'' instead.
  411. .VE
  412. .TP
  413. \fIpathName \fBenable \fIindex\fR
  414. .VS
  415. Change the state of the entry given by \fIindex\fR to \fBnormal\fR
  416. and redisplay the entry using its normal colors.
  417. Returns an empty string.
  418. This command is obsolete and will eventually be removed;
  419. use ``\fIpathName \fBentryconfigure \fIindex\fR \-state normal\fR'' instead.
  420. .VE
  421. .TP
  422. \fIpathName \fBentryconfigure \fIindex\fR \fR?\fIoptions\fR?
  423. This command is similar to the \fBconfigure\fR command, except that
  424. it applies to the options for an individual entry, whereas \fBconfigure\fR
  425. applies to the options for the menu as a whole.
  426. \fIOptions\fR may have any of the values accepted by the \fBadd\fR
  427. widget command.  If \fIoptions\fR are specified, options are modified
  428. as indicated
  429. in the command and the command returns an empty string.
  430. If no \fIoptions\fR are specified, returns a list describing
  431. the current options for entry \fIindex\fR (see \fBTk_ConfigureInfo\fR for
  432. information on the format of this list).
  433. .TP
  434. \fIpathName \fBindex \fIindex\fR
  435. Returns the numerical index corresponding to \fIindex\fR, or
  436. \fBnone\fR if \fIindex\fR was specified as \fBnone\fR.
  437. .TP
  438. \fIpathName \fBinvoke \fIindex\fR
  439. Invoke the action of the menu entry.  See the sections on the
  440. individual entries above for details on what happens.  If the
  441. menu entry is disabled then nothing happens.  If the
  442. entry has a command associated with it then the result of that
  443. command is returned as the result of the \fBinvoke\fR widget
  444. command.  Otherwise the result is an empty string.  Note:  invoking
  445. a menu entry does not automatically unpost the menu.  Normally
  446. the associated menubutton will take care of unposting the menu.
  447. .TP
  448. \fIpathName \fBpost \fIx y\fR
  449. Arrange for the menu to be displayed on the screen at the root-window
  450. coordinates given by \fIx\fR and \fIy\fR.  These coordinates are
  451. adjusted if necessary to guarantee that the entire menu is visible on
  452. the screen.  This command normally returns an empty string.
  453. .VS
  454. If the \fB\-postcommand\fR option has been specified, then its value is
  455. executed as a Tcl script before posting the menu and the result of
  456. that script is returned as the result of the \fBpost\fR widget
  457. command.
  458. If an error returns while executing the command, then the error is
  459. returned without posting the menu.
  460. .VE
  461. .TP
  462. \fIpathName \fBunpost\fR
  463. Unmap the window so that it is no longer displayed.  If a
  464. lower-level cascaded menu is posted, unpost that menu.  Returns an
  465. empty string.
  466. .TP
  467. \fIpathName \fByposition \fIindex\fR
  468. Returns a decimal string giving the y-coordinate within the menu
  469. window of the topmost pixel in the entry specified by \fIindex\fR.
  470.  
  471.  
  472. .SH "DEFAULT BINDINGS"
  473. .PP
  474. .VS
  475. Tk automatically creates class bindings for menus that give them
  476. the following default behavior:
  477. .IP [1]
  478. When the mouse cursor enters a menu, the entry underneath the mouse
  479. cursor is activated;  as the mouse moves around the menu, the active
  480. entry changes to track the mouse.
  481. .IP [2]
  482. When button 1 is released over a menu, the active entry (if any) is invoked.
  483. .IP [3]
  484. A menu can be repositioned on the screen by dragging it with mouse
  485. button 2.
  486. .IP [4]
  487. A number of other bindings are created to support keyboard menu traversal.
  488. See the manual entry for \fBtk_bindForTraversal\fR for details on these
  489. bindings.
  490. .PP
  491. Disabled menu entries are non-responsive:  they don't activate and
  492. ignore mouse button presses and releases.
  493. .PP
  494. The behavior of menus can be changed by defining new bindings for
  495. individual widgets or by redefining the class bindings.
  496. .VE
  497.  
  498. .SH BUGS
  499. .PP
  500. .VS
  501. At present it isn't possible to use the
  502. option database to specify values for the options to individual
  503. entries.
  504. .VE
  505.  
  506. .SH KEYWORDS
  507. menu, widget
  508.