📄 toolbar.itk
字号:
## Toolbar# ----------------------------------------------------------------------## The Toolbar command creates a new window (given by the pathName # argument) and makes it into a Tool Bar widget. Additional options, # described above may be specified on the command line or in the # option database to configure aspects of the Toolbar such as its # colors, font, and orientation. The Toolbar 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 Toolbar is a widget that displays a collection of widgets arranged # either in a row or a column (depending on the value of the -orient # option). This collection of widgets is usually for user convenience # to give access to a set of commands or settings. Any widget may be # placed on a Toolbar. However, command or value-oriented widgets (such # as button, radiobutton, etc.) are usually the most useful kind of # widgets to appear on a Toolbar.## WISH LIST: # This section lists possible future enhancements. ## Toggle between text and image/bitmap so that the toolbar could# display either all text or all image/bitmaps.# Implementation of the -toolbarfile option that allows toolbar# add commands to be read in from a file.# ----------------------------------------------------------------------# AUTHOR: Bill W. Scott EMAIL: bscott@spd.dsccc.com## @(#) $Id: toolbar.itk,v 1.5 2001/08/17 19:05:54 smithc Exp $# ----------------------------------------------------------------------# 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.# ======================================================================## Default resources.#option add *Toolbar*padX 5 widgetDefaultoption add *Toolbar*padY 5 widgetDefaultoption add *Toolbar*orient horizontal widgetDefaultoption add *Toolbar*highlightThickness 0 widgetDefaultoption add *Toolbar*indicatorOn false widgetDefaultoption add *Toolbar*selectColor [. cget -bg] widgetDefault## Usual options.#itk::usual Toolbar { keep -activebackground -activeforeground -background -balloonbackground \ -balloondelay1 -balloondelay2 -balloonfont -balloonforeground \ -borderwidth -cursor -disabledforeground -font -foreground \ -highlightbackground -highlightcolor -highlightthickness \ -insertbackground -insertforeground -selectbackground \ -selectborderwidth -selectcolor -selectforeground -troughcolor}# ------------------------------------------------------------------# TOOLBAR# ------------------------------------------------------------------itcl::class iwidgets::Toolbar { inherit itk::Widget constructor {args} {} destructor {} itk_option define -balloonbackground \ balloonBackground BalloonBackground yellow itk_option define -balloonforeground \ balloonForeground BalloonForeground black itk_option define -balloonfont balloonFont BalloonFont 6x10 itk_option define -balloondelay1 \ balloonDelay1 BalloonDelay1 1000 itk_option define -balloondelay2 \ balloonDelay2 BalloonDelay2 200 itk_option define -helpvariable helpVariable HelpVariable {} itk_option define -orient orient Orient "horizontal" # # The following options implement propogated configurations to # any widget that might be added to us. The problem is this is # not deterministic as someone might add a new kind of widget with # and option like -armbackground, so we would not be aware of # this kind of option. Anyway we support as many of the obvious # ones that we can. They can always configure them with itemconfigures. # itk_option define -activebackground activeBackground Foreground #c3c3c3 itk_option define -activeforeground activeForeground Background Black itk_option define -background background Background #d9d9d9 itk_option define -borderwidth borderWidth BorderWidth 2 itk_option define -cursor cursor Cursor {} itk_option define -disabledforeground \ disabledForeground DisabledForeground #a3a3a3 itk_option define -font \ font Font "-Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-*" itk_option define -foreground foreground Foreground #000000000000 itk_option define -highlightbackground \ highlightBackground HighlightBackground #d9d9d9 itk_option define -highlightcolor highlightColor HighlightColor Black itk_option define -highlightthickness \ highlightThickness HighlightThickness 0 itk_option define -insertforeground insertForeground Background #c3c3c3 itk_option define -insertbackground insertBackground Foreground Black itk_option define -selectbackground selectBackground Foreground #c3c3c3 itk_option define -selectborderwidth selectBorderWidth BorderWidth {} itk_option define -selectcolor selectColor Background #b03060 itk_option define -selectforeground selectForeground Background Black itk_option define -state state State normal itk_option define -troughcolor troughColor Background #c3c3c3 public method add {widgetCommand name args} public method delete {args} public method index {index} public method insert {beforeIndex widgetCommand name args} public method itemcget {index args} public method itemconfigure {index args} public method _resetBalloonTimer {} public method _startBalloonDelay {window} public method _stopBalloonDelay {window balloonClick} private method _deleteWidgets {index1 index2} private method _addWidget {widgetCommand name args} private method _index {toolList index} private method _getAttachedOption {optionListName widget args retValue} private method _setAttachedOption {optionListName widget option args} private method _packToolbar {} public method hideHelp {} public method showHelp {window} public method showBalloon {window} public method hideBalloon {} private variable _balloonTimer 0 private variable _balloonAfterID 0 private variable _balloonClick false private variable _interior {} private variable _initialMapping 1 ;# Is this the first mapping? private variable _toolList {} ;# List of all widgets on toolbar private variable _opts ;# New options for child widgets private variable _currHelpWidget {} ;# Widget currently displaying help for private variable _hintWindow {} ;# Balloon help bubble. # list of options we want to propogate to widgets added to toolbar. private common _optionList { -activebackground \ -activeforeground \ -background \ -borderwidth \ -cursor \ -disabledforeground \ -font \ -foreground \ -highlightbackground \ -highlightcolor \ -highlightthickness \ -insertbackground \ -insertforeground \ -selectbackground \ -selectborderwidth \ -selectcolor \ -selectforeground \ -state \ -troughcolor \ }}# ------------------------------------------------------------------# CONSTRUCTOR # ------------------------------------------------------------------itcl::body iwidgets::Toolbar::constructor {args} { component hull configure -borderwidth 0 set _interior $itk_interior # # Handle configs # eval itk_initialize $args # build balloon help window set _hintWindow [toplevel $itk_component(hull).balloonHintWindow] wm withdraw $_hintWindow label $_hintWindow.label \ -foreground $itk_option(-balloonforeground) \ -background $itk_option(-balloonbackground) \ -font $itk_option(-balloonfont) \ -relief raised \ -borderwidth 1 pack $_hintWindow.label # ... Attach help handler to this widget bind toolbar-help-$itk_component(hull) \ <Enter> "+[itcl::code $this showHelp %W]" bind toolbar-help-$itk_component(hull) \ <Leave> "+[itcl::code $this hideHelp]" # ... Set up Microsoft style balloon help display. set _balloonTimer $itk_option(-balloondelay1) bind $_interior \ <Leave> "+[itcl::code $this _resetBalloonTimer]" bind toolbar-balloon-$itk_component(hull) \ <Enter> "+[itcl::code $this _startBalloonDelay %W]" bind toolbar-balloon-$itk_component(hull) \ <Leave> "+[itcl::code $this _stopBalloonDelay %W false]" bind toolbar-balloon-$itk_component(hull) \ <Button-1> "+[itcl::code $this _stopBalloonDelay %W true]"}## Provide a lowercase access method for the Toolbar class#proc ::iwidgets::toolbar {pathName args} { uplevel ::iwidgets::Toolbar $pathName $args}# ------------------------------------------------------------------# DESTURCTOR# ------------------------------------------------------------------itcl::body iwidgets::Toolbar::destructor {} { if {$_balloonAfterID != 0} {after cancel $_balloonAfterID}}# ------------------------------------------------------------------# OPTIONS# ------------------------------------------------------------------# ------------------------------------------------------------------# OPTION -balloonbackground# ------------------------------------------------------------------itcl::configbody iwidgets::Toolbar::balloonbackground { if { $_hintWindow != {} } { if { $itk_option(-balloonbackground) != {} } { $_hintWindow.label configure \ -background $itk_option(-balloonbackground) } }}# ------------------------------------------------------------------# OPTION -balloonforeground# ------------------------------------------------------------------itcl::configbody iwidgets::Toolbar::balloonforeground { if { $_hintWindow != {} } { if { $itk_option(-balloonforeground) != {} } { $_hintWindow.label configure \ -foreground $itk_option(-balloonforeground) } }}# ------------------------------------------------------------------# OPTION -balloonfont# ------------------------------------------------------------------itcl::configbody iwidgets::Toolbar::balloonfont { if { $_hintWindow != {} } { if { $itk_option(-balloonfont) != {} } { $_hintWindow.label configure \ -font $itk_option(-balloonfont) } }}# ------------------------------------------------------------------# OPTION: -orient## Position buttons either horizontally or vertically.# ------------------------------------------------------------------itcl::configbody iwidgets::Toolbar::orient { switch $itk_option(-orient) { "horizontal" - "vertical" { _packToolbar } default {error "Invalid orientation. Must be either \ horizontal or vertical" } }}# ------------------------------------------------------------------# METHODS# ------------------------------------------------------------------ # -------------------------------------------------------------# METHOD: add widgetCommand name ?option value?## Adds a widget with the command widgetCommand whose name is # name to the Toolbar. If widgetCommand is radiobutton # or checkbutton, its packing is slightly padded to match the # geometry of button widgets.# -------------------------------------------------------------itcl::body iwidgets::Toolbar::add { widgetCommand name args } { eval "_addWidget $widgetCommand $name $args" lappend _toolList $itk_component($name) if { $widgetCommand == "radiobutton" || \ $widgetCommand == "checkbutton" } { set iPad 1 } else { set iPad 0 } # repack the tool bar _packToolbar
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -