📄 hierarchy.itk
字号:
# Hierarchy# ----------------------------------------------------------------------# Hierarchical data viewer. Manages a list of nodes that can be# expanded or collapsed. Individual nodes can be highlighted.# Clicking with the right mouse button on any item brings up a# special item menu. Clicking on the background area brings up# a different popup menu.# ----------------------------------------------------------------------# AUTHOR: Michael J. McLennan# Bell Labs Innovations for Lucent Technologies# mmclennan@lucent.com## Mark L. Ulferts# DSC Communications# mulferts@austin.dsccc.com## RCS: $Id: hierarchy.itk 144 2003-02-05 10:56:26Z mdejong $# ----------------------------------------------------------------------# Copyright (c) 1996 Lucent Technologies# ======================================================================# Permission to use, copy, modify, and distribute this software and its# documentation for any purpose and without fee is hereby granted,# provided that the above copyright notice appear in all copies and that# both that the copyright notice and warranty disclaimer appear in# supporting documentation, and that the names of Lucent Technologies# any of their entities not be used in advertising or publicity# pertaining to distribution of the software without specific, written# prior permission.## Lucent Technologies disclaims all warranties with regard to this# software, including all implied warranties of merchantability and# fitness. In no event shall Lucent Technologies 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.## ----------------------------------------------------------------------# Copyright (c) 1996 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 Hierarchy { keep -cursor -textfont -font keep -background -foreground -textbackground keep -selectbackground -selectforeground }# ------------------------------------------------------------------# HIERARCHY# ------------------------------------------------------------------class iwidgets::Hierarchy { inherit iwidgets::Scrolledwidget constructor {args} {} destructor {} itk_option define -alwaysquery alwaysQuery AlwaysQuery 0 itk_option define -closedicon closedIcon Icon {} itk_option define -dblclickcommand dblClickCommand Command {} itk_option define -expanded expanded Expanded 0 itk_option define -filter filter Filter 0 itk_option define -font font Font \ -*-Courier-Medium-R-Normal--*-120-*-*-*-*-*-* itk_option define -height height Height 0 itk_option define -iconcommand iconCommand Command {} itk_option define -icondblcommand iconDblCommand Command {} itk_option define -imagecommand imageCommand Command {} itk_option define -imagedblcommand imageDblCommand Command {} itk_option define -imagemenuloadcommand imageMenuLoadCommand Command {} itk_option define -markbackground markBackground Foreground #a0a0a0 itk_option define -markforeground markForeground Background Black itk_option define -nodeicon nodeIcon Icon {} itk_option define -openicon openIcon Icon {} itk_option define -querycommand queryCommand Command {} itk_option define -selectcommand selectCommand Command {} itk_option define -selectbackground selectBackground Foreground #c3c3c3 itk_option define -selectforeground selectForeground Background Black itk_option define -textmenuloadcommand textMenuLoadCommand Command {} itk_option define -visibleitems visibleItems VisibleItems 80x24 itk_option define -width width Width 0 public { method clear {} method collapse {node} method current {} method draw {{when -now}} method expand {node} method expanded {node} method expState { } method mark {op args} method prune {node} method refresh {node} method selection {op args} method toggle {node} method bbox {index} method compare {index1 op index2} method debug {args} {eval $args} method delete {first {last {}}} method dlineinfo {index} method dump {args} method get {index1 {index2 {}}} method index {index} method insert {args} method scan {option args} method search {args} method see {index} method tag {op args} method window {option args} method xview {args} method yview {args} } protected { method _contents {uid} method _post {x y} method _drawLevel {node indent} method _select {x y} method _deselectSubNodes {uid} method _deleteNodeInfo {uid} method _getParent {uid} method _getHeritage {uid} method _isInternalTag {tag} method _iconSelect {node icon} method _iconDblSelect {node icon} method _imageSelect {node} method _imageDblClick {node} method _imagePost {node image type x y} method _double {x y} } private { variable _filterCode "" ;# Compact view flag. variable _hcounter 0 ;# Counter for hierarchy icons variable _icons ;# Array of user icons by uid variable _images ;# Array of our icons by uid variable _indents ;# Array of indentation by uid variable _marked ;# Array of marked nodes by uid variable _markers "" ;# List of markers for level being drawn variable _nodes ;# List of subnodes by uid variable _pending "" ;# Pending draw flag variable _posted "" ;# List of tags at posted menu position variable _selected ;# Array of selected nodes by uid variable _tags ;# Array of user tags by uid variable _text ;# Array of displayed text by uid variable _states ;# Array of selection state by uid variable _ucounter 0 ;# Counter for user icons }}## Provide a lowercased access method for the Hierarchy class.# proc ::iwidgets::hierarchy {pathName args} { uplevel ::iwidgets::Hierarchy $pathName $args}## Use option database to override default resources of base classes.#option add *Hierarchy.menuCursor arrow widgetDefaultoption add *Hierarchy.labelPos n widgetDefaultoption add *Hierarchy.tabs 30 widgetDefault# ------------------------------------------------------------------# CONSTRUCTOR# ------------------------------------------------------------------body iwidgets::Hierarchy::constructor {args} { itk_option remove iwidgets::Labeledwidget::state # # Our -width and -height options are slightly different than # those implemented by our base class, so we're going to # remove them and redefine our own. # itk_option remove iwidgets::Scrolledwidget::width itk_option remove iwidgets::Scrolledwidget::height # # Create a clipping frame which will provide the border for # relief display. # itk_component add clipper { frame $itk_interior.clipper } { usual keep -borderwidth -relief -highlightthickness -highlightcolor rename -highlightbackground -background background Background } grid $itk_component(clipper) -row 0 -column 0 -sticky nsew grid rowconfigure $_interior 0 -weight 1 grid columnconfigure $_interior 0 -weight 1 # # Create a text widget for displaying our hierarchy. # itk_component add list { text $itk_component(clipper).list -wrap none -cursor center_ptr \ -state disabled -width 1 -height 1 \ -xscrollcommand \ [code $this _scrollWidget $itk_interior.horizsb] \ -yscrollcommand \ [code $this _scrollWidget $itk_interior.vertsb] \ -borderwidth 0 -highlightthickness 0 } { usual keep -spacing1 -spacing2 -spacing3 -tabs rename -font -textfont textFont Font rename -background -textbackground textBackground Background ignore -highlightthickness -highlightcolor ignore -insertbackground -insertborderwidth ignore -insertontime -insertofftime -insertwidth ignore -selectborderwidth ignore -borderwidth } grid $itk_component(list) -row 0 -column 0 -sticky nsew grid rowconfigure $itk_component(clipper) 0 -weight 1 grid columnconfigure $itk_component(clipper) 0 -weight 1 # # Configure the command on the vertical scroll bar in the base class. # $itk_component(vertsb) configure \ -command [code $itk_component(list) yview] # # Configure the command on the horizontal scroll bar in the base class. # $itk_component(horizsb) configure \ -command [code $itk_component(list) xview] # # Configure our text component's tab settings for twenty levels. # set tabs "" for {set i 1} {$i < 20} {incr i} { lappend tabs [expr $i*12+4] } $itk_component(list) configure -tabs $tabs # # Add popup menus that can be configured by the user to add # new functionality. # itk_component add itemMenu { menu $itk_component(list).itemmenu -tearoff 0 } { usual ignore -tearoff rename -cursor -menucursor menuCursor Cursor } itk_component add bgMenu { menu $itk_component(list).bgmenu -tearoff 0 } { usual ignore -tearoff rename -cursor -menucursor menuCursor Cursor } # # Adjust the bind tags to remove the class bindings. Also, add # bindings for mouse button 1 to do selection and button 3 to # display a popup. # bindtags $itk_component(list) [list $itk_component(list) . all] bind $itk_component(list) <ButtonPress-1> \ [code $this _select %x %y] bind $itk_component(list) <Double-1> \ [code $this _double %x %y] bind $itk_component(list) <ButtonPress-3> \ [code $this _post %x %y] # # Initialize the widget based on the command line options. # eval itk_initialize $args}# ------------------------------------------------------------------# DESTRUCTOR# ------------------------------------------------------------------body iwidgets::Hierarchy::destructor {} { if {$_pending != ""} { after cancel $_pending }}# ------------------------------------------------------------------# OPTIONS# ------------------------------------------------------------------# ------------------------------------------------------------------# OPTION: -font## Font used for text in the list.# ------------------------------------------------------------------configbody iwidgets::Hierarchy::font { $itk_component(list) tag configure info \ -font $itk_option(-font) -spacing1 6}# ------------------------------------------------------------------# OPTION: -selectbackground## Background color scheme for selected nodes.# ------------------------------------------------------------------configbody iwidgets::Hierarchy::selectbackground { $itk_component(list) tag configure hilite \ -background $itk_option(-selectbackground)}# ------------------------------------------------------------------# OPTION: -selectforeground## Foreground color scheme for selected nodes.# ------------------------------------------------------------------configbody iwidgets::Hierarchy::selectforeground { $itk_component(list) tag configure hilite \ -foreground $itk_option(-selectforeground)}# ------------------------------------------------------------------# OPTION: -markbackground## Background color scheme for marked nodes.# ------------------------------------------------------------------configbody iwidgets::Hierarchy::markbackground { $itk_component(list) tag configure lowlite \ -background $itk_option(-markbackground)}# ------------------------------------------------------------------# OPTION: -markforeground## Foreground color scheme for marked nodes.# ------------------------------------------------------------------configbody iwidgets::Hierarchy::markforeground { $itk_component(list) tag configure lowlite \ -foreground $itk_option(-markforeground)}# ------------------------------------------------------------------# OPTION: -querycommand## Command executed to query the contents of each node. If this # command contains "%n", it is replaced with the name of the desired # node. In its simpilest form it should return the children of the # given node as a list which will be depicted in the display.## Since the names of the children are used as tags in the underlying # text widget, each child must be unique in the hierarchy. Due to# the unique requirement, the nodes shall be reffered to as uids # or uid in the singular sense.# # {uid [uid ...]}#
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -