<> ---- **Introduction** The [tklib] library contains a '''menubar ''' package that implements a menubar class. This class can be used to create and manage menubars in toplevel windows. The class doesn't depend on a widget framework and therefore can be used with or without a framework (e.g. Bwidget, IWidget, Snit, etc.). Some of the features of this package are: * A tagging system that simplifies access to menu entries in the menu tree. * Support for user defined tags that depend on the toplevel window context. * A simplified and uniform interface for all callback commands. * Namespace support for all callback commands so callback commands can be easily grouped into namespaces. * Support for hiding and exposing menus on the menubar. * A simplified method for creating radiobutton groups. * Automatic management of state variables for checkbuttons and radiobuttons. * Scope control for the state variables of checkbuttons and radiobuttons. * Tearoff menu management that ensures only one tearoff menu is created. * Support for dynamic menu extension to simplify the creation of recent document menus. * Support for saving and restoring dynamic menu extensions. The package is written in pure Tcl/Tk but it uses TclOO so 8.6 or greater is suggested. -- [Tom Krehbiel] ---- **Illustrations** The screen shots in the following examples were created using the demo code that is part of the menubar package. You can use this code as a starting point for implementing any special feature you my need for your application. ***SCOPE CONTROL*** The following screen shots illustrate what is meant by scope control in the menubar class. In the screen shots below the same instance of the menubar class has been installed in each of the two toplevel windows. Below the windows are two menus that have been torn off from the same location in the menubar of each of the toplevel windows. ****Global Scope Example**** In this first screen shot illustrates what is meant by global scope. Each of these menus was created using the global (i.e. default) scope. As a result the value of the items are the same for both menus and changing one menu will cause the other menu to also be changed. [menubar_image1.jpg] ****Local Scope Example**** This second screen shot is similar to the first but the menus have been created using the local scope modifier. Notice that even though the menus have identical items the value of the items on the left are different from the items on the right. These menus have values that are scoped local to their associated toplevel window. [menubar_image2.jpg] ****Notebook Tab Scope Example**** The following two screen shots illustrate how tab selection can be used to control the value settings of check and radio buttons. Notice that in the first screen shot tab "One" is selected in both toplevel windows and in the second screen shot tab "Two" is selected. [menubar_image3.jpg] [menubar ScreenShot1] ***DYNAMIC MENU EXTENSION*** This screen shot illustrates dynamic menu extension. This menu has a dynamic extension that starts at the horizontal separator. All of the "Item"s and the "Mark" were added by clicking on the appropriate command buttons. The "Mark" was also moved up from its initial location at the end of the menu. This demo code is designed to test and illustrate the use of the group.xxx commands but these commands can of course also be used without any visible menu items. [menubar ScreenShot2] ---- **menubar man page** <> [comment {-*- tcl -*- doctools manpage}] [manpage_begin menubar n 0.5] [copyright "2009 Tom Krehbiel All rights reserved."] [titledesc "Creates an instance of the [emph menubar] Class."] [moddesc {Create and manipulate menubars}] [require Tcl 8.6] [require Tk 8.6] [require menubar [opt 0.5]] [description] [list_begin definitions] [call [cmd {menubar new}] [opt options]] [list_end] [para] Create and return a new instance of the menubar class. The menubar class encapsulates the definition, installation and dynamic behavior of a menubar. The class doesn't depend on a widget framework and therefore can be used with or without a framework (e.g. Bwidget, IWidget, Snit, etc.). Unlike other Tk widget commands, the menubar command doesn't have a [emph pathName] argument because menubars are handled by the window manager (i.e. wm) and not the application. [section {Options}] The following options can be passed to the [emph {menubar new}] command. [para] These options are inherited from the Tk menu command, their effect is platform specific. [list_begin options] [opt_def [uri http://docs.activestate.com/activetcl/8.5/tcl/TkCmd/options.htm#M-activebackground -activebackground]] [opt_def [uri http://docs.activestate.com/activetcl/8.5/tcl/TkCmd/options.htm#M-activeborderwidth -activeborderwidth]] [opt_def [uri http://docs.activestate.com/activetcl/8.5/tcl/TkCmd/options.htm#M-activeforeground -activeforeground]] [opt_def [uri http://docs.activestate.com/activetcl/8.5/tcl/TkCmd/options.htm#M-background -background]] [opt_def [uri http://docs.activestate.com/activetcl/8.5/tcl/TkCmd/options.htm#M-borderwidth -borderwidth]] [opt_def [uri http://docs.activestate.com/activetcl/8.5/tcl/TkCmd/options.htm#M-cursor -cursor]] [opt_def [uri http://docs.activestate.com/activetcl/8.5/tcl/TkCmd/options.htm#M-disabledforeground -disabledforeground]] [opt_def [uri http://docs.activestate.com/activetcl/8.5/tcl/TkCmd/options.htm#M-font -font]] [opt_def [uri http://docs.activestate.com/activetcl/8.5/tcl/TkCmd/options.htm#M-foreground -foreground]] [opt_def [uri http://docs.activestate.com/activetcl/8.5/tcl/TkCmd/options.htm#M-relief -relief]] [list_end] [section Introduction] [para] An instance of the menubar class provides methods for compiling a description of the menubar, configuring menu items and installing the menubar in toplevel windows. [para] A menubar can be thought of as a tree of cascading menus. Users define a menubar using a language that results in a human readable description of a menubar. The description of the menubar is then compiled by an instance of the menubar class after which it can be installed in one or more toplevel windows. [para] The menubar class provides many unique capabilities that are not found in other tcl/tk menubar implementation. Some of these are: [list_begin itemized] [item] A tagging system that simplifies access to menu entries in the menu tree. [item] Support for user defined tags that depend on the toplevel window context. [item] A simplified and uniform interface for all callback commands. [item] Namespace support for all callback commands so callback commands can be easily grouped into namespaces. [item] Support for hiding and exposing menus on the menubar. [item] A simplified method for creating radiobutton groups. [item] Automatic management of state variables for checkbuttons and radiobuttons. [item] Scope control for the state variables of checkbuttons and radiobuttons. [item] Tear-off menu management that ensures only one tearoff menu is created. [item] Support for dynamic menu extension to simplify the creation of recent document menus. [item] Support for saving and restoring dynamic menu extensions. [list_end] [section Terminology] [list_begin definitions] [def MENUBAR] The visible rendering of a menubar in a toplevel window is a horizontally group of cascading Tk menus. [def MENU] A menu is an ordered list of items that is rendered vertically. Menus are not visible until a user preforms some action (normally a event). A menu may contain any number of child menus that are rendered as cascading menus. Cascading menus are rendered next to the parent menu when they are activated. [def {MENU ENTRY}] A menu contains an ordered list of items called entries. Menu entries have a type and the menubar class supports the following 6 entry types: [emph Command], [emph Checkbutton], [emph Radiobutton], [emph Separator], [emph Group] and [emph Menu]. [def {ENTRY LABEL}] Each menu entry has a visible string that is called the entry label. [def {TAG}] A tag is name that is normally used to referr to an item in a menu tree. A tag name is an alphanumeric character string that may include the underscore character. Menu tree tags are defined for all nodes and leafs in a menu tree. This provides a flat abstraction of the tree and simplifies item referencing in menubar methods. Without this abstraction it would be necessary to reference menu elements using a tree path which could change at run-time. The menubar class also has a method that can create a user defined tag. User defined tags store values that change based on the currently active toplevel window. User defined tags can be used to store widget pathnames use by callback code so that output can be routed to the appropriate toplevel window. [list_end] [section Methods] [list_begin definitions] [call [arg mBarInst] [cmd define] [arg body]] Compiles [emph body] into a tree of menu entries which define the visual layout of the menubar. The [emph body] argument describes the layout using the following syntax, where the elements of the syntax are described below. [para] [emph {body == definitions}] [example_begin] definitions ::= { | | } ignore ::= { | | # } definition ::= { | | | | | } command ::=