📄 menubar.itk
字号:
## Menubar widget# ----------------------------------------------------------------------# The Menubar command creates a new window (given by the pathName # argument) and makes it into a Pull down menu widget. Additional # options, described above may be specified on the command line or # in the option database to configure aspects of the Menubar such # as its colors and font. The Menubar command returns its pathName # argument. At the time this command is invoked, there must not exist # a window named pathName, but pathName's parent must exist.# # A Menubar is a widget that simplifies the task of creating # menu hierarchies. It encapsulates a frame widget, as well # as menubuttons, menus, and menu entries. The Menubar allows # menus to be specified and refer enced in a more consistent # manner than using Tk to build menus directly. First, Menubar# allows a menu tree to be expressed in a hierachical "language". # The Menubar accepts a menuButtons option that allows a list of # menubuttons to be added to the Menubar. In turn, each menubutton# accepts a menu option that spec ifies a list of menu entries # to be added to the menubutton's menu (as well as an option # set for the menu). Cascade entries in turn, accept a menu # option that specifies a list of menu entries to be added to # the cascade's menu (as well as an option set for the menu). In # this manner, a complete menu grammar can be expressed to the # Menubar. Additionally, the Menubar allows each component of # the Menubar system to be referenced by a simple componentPathName # syntax. Finally, the Menubar extends the option set of menu # entries to include the helpStr option used to implement status # bar help.## WISH LIST:# This section lists possible future enhancements.## ----------------------------------------------------------------------# AUTHOR: Bill W. Scott EMAIL: bscott@spd.dsccc.com## @(#) $Id: menubar.itk 144 2003-02-05 10:56:26Z mdejong $# ----------------------------------------------------------------------# Copyright (c) 1995 DSC Technologies Corporation# ======================================================================# Permission to use, copy, modify, distribute and license this software # and its documentation for any purpose, and without fee or written # agreement with DSC, is hereby granted, provided that the above copyright # notice appears in all copies and that both the copyright notice and # warranty disclaimer below appear in supporting documentation, and that # the names of DSC Technologies Corporation or DSC Communications # Corporation not be used in advertising or publicity pertaining to the # software without specific, written prior permission.# # DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL # DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS # SOFTWARE.# ======================================================================## Usual options.#itk::usual Menubar { keep -activebackground -activeborderwidth -activeforeground \ -anchor -background -borderwidth -cursor -disabledforeground \ -font -foreground -highlightbackground -highlightthickness \ -highlightcolor -justify -padx -pady -wraplength}class iwidgets::Menubar { inherit itk::Widget constructor { args } {} itk_option define -foreground foreground Foreground Black itk_option define -activebackground activeBackground Foreground "#ececec" itk_option define -activeborderwidth activeBorderWidth BorderWidth 2 itk_option define -activeforeground activeForeground Background black itk_option define -anchor anchor Anchor center itk_option define -borderwidth borderWidth BorderWidth 2 itk_option define \ -disabledforeground disabledForeground DisabledForeground #a3a3a3 itk_option define \ -font font Font "-Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-*" itk_option define \ -highlightbackground highlightBackground HighlightBackground #d9d9d9 itk_option define -highlightcolor highlightColor HighlightColor Black itk_option define \ -highlightthickness highlightThickness HighlightThickness 0 itk_option define -justify justify Justify center itk_option define -padx padX Pad 4p itk_option define -pady padY Pad 3p itk_option define -wraplength wrapLength WrapLength 0 itk_option define -menubuttons menuButtons MenuButtons {} itk_option define -helpvariable helpVariable HelpVariable {} public { method add { type path args } { } method delete { args } { } method index { path } { } method insert { beforeComponent type name args } method invoke { entryPath } { } method menucget { args } { } method menuconfigure { path args } { } method path { args } { } method type { path } { } method yposition { entryPath } { } } private { method menubutton { menuName args } { } method options { args } { } method command { cmdName args } { } method checkbutton { chkName args } { } method radiobutton { radName args } { } method separator { sepName args } { } method cascade { casName args } { } method _helpHandler { menuPath } { } method _addMenuButton { buttonName args} { } method _insertMenuButton { beforeMenuPath buttonName args} { } method _makeMenuButton {buttonName args} { } method _makeMenu \ { componentName widgetName menuPath menuEvalStr } { } method _substEvalStr { evalStr } { } method _deleteMenu { menuPath {menuPath2 {}} } { } method _deleteAMenu { path } { } method _addEntry { type path args } { } method _addCascade { tkMenuPath path args } { } method _insertEntry { beforeEntryPath type name args } { } method _insertCascade { bfIndex tkMenuPath path args } { } method _deleteEntry { entryPath {entryPath2 {}} } { } method _configureMenu { path tkPath {option {}} args } { } method _configureMenuOption { type path args } { } method _configureMenuEntry { path index {option {}} args } { } method _unsetPaths { parent } { } method _entryPathToTkMenuPath {entryPath} { } method _getTkIndex { tkMenuPath tkIndex} { } method _getPdIndex { tkMenuPath tkIndex } { } method _getMenuList { } { } method _getEntryList { menu } { } method _parsePath { path } { } method _getSymbolicPath { parent segment } { } method _getCallerLevel { } variable _parseLevel 0 ;# The parse level depth variable _callerLevel #0 ;# abs level of caller variable _pathMap ;# Array indexed by Menubar's path ;# naming, yields tk menu path variable _entryIndex -1 ;# current entry help is displayed ;# for during help <motion> events variable _tkMenuPath ;# last tk menu being added to variable _ourMenuPath ;# our last valid path constructed. variable _menuOption ;# The -menu option variable _helpString ;# The -helpstr optio }}## Use option database to override default resources.#option add *Menubar*Menu*tearOff false widgetDefaultoption add *Menubar*Menubutton*relief flat widgetDefaultoption add *Menubar*Menu*relief raised widgetDefault## Provide a lowercase access method for the menubar class#proc ::iwidgets::menubar { args } { uplevel ::iwidgets::Menubar $args}# ------------------------------------------------------------------# CONSTRUCTOR# ------------------------------------------------------------------body iwidgets::Menubar::constructor { args } { component hull configure -borderwidth 0 # # Create the Menubar Frame that will hold the menus. # # might want to make -relief and -bd options with defaults itk_component add menubar { frame $itk_interior.menubar -relief raised -bd 2 } { keep -cursor -background -width -height } pack $itk_component(menubar) -fill both -expand yes # Map our pathname to class to the actual menubar frame set _pathMap(.) $itk_component(menubar) eval itk_initialize $args # # HACK HACK HACK # Tk expects some variables to be defined and due to some # unknown reason we confuse its normal ordering. So, if # the user creates a menubutton with no menu it will fail # when clicked on with a "Error: can't read $tkPriv(oldGrab): # no such element in array". So by setting it to null we # avoid this error. uplevel #0 "set tkPriv(oldGrab) {}"}# ------------------------------------------------------------------# OPTIONS# ------------------------------------------------------------------# This first set of options are for configuring menus and/or menubuttons# at the menu level.## ------------------------------------------------------------------# OPTION -foreground## menu# menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::foreground {}# ------------------------------------------------------------------# OPTION -activebackground## menu# menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::activebackground {}# ------------------------------------------------------------------# OPTION -activeborderwidth## menu# ------------------------------------------------------------------configbody iwidgets::Menubar::activeborderwidth {}# ------------------------------------------------------------------# OPTION -activeforeground## menu# menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::activeforeground {}# ------------------------------------------------------------------# OPTION -anchor## menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::anchor {}# ------------------------------------------------------------------# OPTION -borderwidth## menu# menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::borderwidth {}# ------------------------------------------------------------------# OPTION -disabledforeground## menu# menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::disabledforeground {}# ------------------------------------------------------------------# OPTION -font## menu# menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::font {}# ------------------------------------------------------------------# OPTION -highlightbackground## menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::highlightbackground {}# ------------------------------------------------------------------# OPTION -highlightcolor## menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::highlightcolor {}# ------------------------------------------------------------------# OPTION -highlightthickness## menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::highlightthickness {}# ------------------------------------------------------------------# OPTION -justify## menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::justify {}# ------------------------------------------------------------------# OPTION -padx## menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::padx {}# ------------------------------------------------------------------# OPTION -pady## menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::pady {}# ------------------------------------------------------------------# OPTION -wraplength## menubutton# ------------------------------------------------------------------configbody iwidgets::Menubar::wraplength {}# ------------------------------------------------------------------# OPTION -menubuttons## The menuButton option is a string which specifies the arrangement # of menubuttons on the Menubar frame. Each menubutton entry is # delimited by the newline character. Each entry is treated as # an add command to the Menubar. ## ------------------------------------------------------------------configbody iwidgets::Menubar::menubuttons { if { $itk_option(-menubuttons) != {} } { # IF one exists already, delete the old one and create # a new one if { ! [catch {_parsePath .0}] } { delete .0 .last } # # Determine the context level to evaluate the option string at # set _callerLevel [_getCallerLevel] # # Parse the option string in their scope, then execute it in # our scope. # incr _parseLevel _substEvalStr itk_option(-menubuttons) eval $itk_option(-menubuttons) # reset so that we know we aren't parsing in a scope currently. incr _parseLevel -1 }}# ------------------------------------------------------------------# OPTION -helpvariable## Specifies the global variable to update whenever the mouse is in # motion over a menu entry. This global variable is updated with the # current value of the active menu entry's helpStr. Other widgets # can "watch" this variable with the trace command, or as is the # case with entry or label widgets, they can set their textVariable # to the same global variable. This allows for a simple implementation # of a help status bar. Whenever the mouse leaves a menu entry, # the helpVariable is set to the empty string {}.# ------------------------------------------------------------------configbody iwidgets::Menubar::helpvariable { if {"" != $itk_option(-helpvariable) && ![string match ::* $itk_option(-helpvariable)] && ![string match @itcl* $itk_option(-helpvariable)]} { set itk_option(-helpvariable) "::$itk_option(-helpvariable)" }}# -------------------------------------------------------------## METHOD: add type path args## Adds either a menu to the menu bar or a menu entry to a# menu pane.## If the type is one of cascade, checkbutton, command,# radiobutton, or separator it adds a new entry to the bottom# of the menu denoted by the menuPath prefix of componentPath-
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -