📄 panedwindow.itk
字号:
## Panedwindow# ----------------------------------------------------------------------# Implements a multiple paned window widget capable of orienting the panes# either vertically or horizontally. Each pane is itself a frame acting# as a child site for other widgets. The border separating each pane # contains a sash which allows user positioning of the panes relative to# one another. ## ----------------------------------------------------------------------# AUTHOR: Mark L. Ulferts EMAIL: mulferts@austin.dsccc.com## @(#) $Id: panedwindow.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 Panedwindow { keep -background -cursor -sashcursor}# ------------------------------------------------------------------# PANEDWINDOW# ------------------------------------------------------------------class iwidgets::Panedwindow { inherit itk::Widget constructor {args} {} itk_option define -orient orient Orient horizontal itk_option define -sashborderwidth sashBorderWidth SashBorderWidth 2 itk_option define -sashcursor sashCursor SashCursor crosshair itk_option define -sashwidth sashWidth SashWidth 10 itk_option define -sashheight sashHeight SashHeight 10 itk_option define -thickness thickness Thickness 3 itk_option define -sashindent sashIndent SashIndent -10 public method index {index} public method childsite {args} public method fraction {percentage1 percentage2 args} public method add {tag args} public method insert {index tag args} public method delete {index} public method hide {index} public method show {index} public method paneconfigure {index args} public method reset {} protected method _pwConfigureEventHandler {width height} protected method _startGrip {where num} protected method _endGrip {where num} protected method _configGrip {where num} protected method _handleGrip {where num} protected method _moveSash {where num} private method _setFracArray {} private method _setActivePanes {} private method _calcFraction {where num} private method _makeSashes {} private method _placeSash {i} private method _placePanes {{start 0} {end end}} private variable _initialized 0 ;# Denotes initialized state. private variable _panes {} ;# List of panes. private variable _activePanes {} ;# List of active panes. private variable _sashes {} ;# List of sashes. private variable _separators {} ;# List of separators. private variable _frac ;# Array of fraction percentages. private variable _lowerlimit ;# Margin distance above/left of sash. private variable _upperlimit ;# Margin distance below/right of sash. private variable _dimension ;# Width/Height at start of drag. private variable _sashloc ;# Array of dist of sash from above/left. private variable _pixels ;# Array of dist of sash from above/left. private variable _minheight ;# Array of min heights for panes. private variable _minsashmoved ;# Lowest sash moved during dragging. private variable _maxsashmoved ;# Highest sash moved during dragging. private variable _dragging 0 ;# Boolean for dragging enabled. private variable _movecount 0 ;# Kludge counter to get sashes to ;# display without calling update ;# idletasks too often. private variable _width 0 ;# hull's width. private variable _height 0 ;# hull's height. private variable _unique -1 ;# Unique number for pane names.}## Provide a lowercased access method for the Panedwindow class.# proc ::iwidgets::panedwindow {pathName args} { uplevel ::iwidgets::Panedwindow $pathName $args}## Use option database to override default resources of base classes.#option add *Panedwindow.width 10 widgetDefaultoption add *Panedwindow.height 10 widgetDefault# ------------------------------------------------------------------# CONSTRUCTOR# ------------------------------------------------------------------body iwidgets::Panedwindow::constructor {args} { itk_option add hull.width hull.height pack propagate $itk_component(hull) no # # Add binding for the configure event. # bind pw-config-$this <Configure> [code $this _pwConfigureEventHandler %w %h] bindtags $itk_component(hull) \ [linsert [bindtags $itk_component(hull)] 0 pw-config-$this] eval itk_initialize $args}# ------------------------------------------------------------------# OPTIONS# ------------------------------------------------------------------# ------------------------------------------------------------------# OPTION: -orient## Specifies the orientation of the sashes. Once the paned window# has been mapped, set the sash bindings and place the panes.# ------------------------------------------------------------------configbody iwidgets::Panedwindow::orient { if {$_initialized} { switch $itk_option(-orient) { vertical { for {set i 1} {$i < [llength $_activePanes]} {incr i} { bind $itk_component(sash$i) <Button-1> \ [code $this _startGrip %x $i] bind $itk_component(sash$i) <B1-Motion> \ [code $this _handleGrip %x $i] bind $itk_component(sash$i) <B1-ButtonRelease-1> \ [code $this _endGrip %x $i] bind $itk_component(sash$i) <Configure> \ [code $this _configGrip %x $i] } _setFracArray _makeSashes _placePanes } horizontal { for {set i 1} {$i < [llength $_activePanes]} {incr i} { bind $itk_component(sash$i) <Button-1> \ [code $this _startGrip %y $i] bind $itk_component(sash$i) <B1-Motion> \ [code $this _handleGrip %y $i] bind $itk_component(sash$i) <B1-ButtonRelease-1> \ [code $this _endGrip %y $i] bind $itk_component(sash$i) <Configure> \ [code $this _configGrip %y $i] } _setFracArray _makeSashes _placePanes } default { error "bad orientation option \"$itk_option(-orient)\":\ should be horizontal or vertical" } } }}# ------------------------------------------------------------------# OPTION: -sashborderwidth## Specifies a non-negative value indicating the width of the 3-D# border to draw around the outside of the sash.# ------------------------------------------------------------------configbody iwidgets::Panedwindow::sashborderwidth { set pixels [winfo pixels $itk_component(hull) \ $itk_option(-sashborderwidth)] set itk_option(-sashborderwidth) $pixels if {$_initialized} { for {set i 1} {$i < [llength $_activePanes]} {incr i} { $itk_component(sash$i) configure \ -borderwidth $itk_option(-sashborderwidth) } }}# ------------------------------------------------------------------# OPTION: -sashcursor## Specifies the type of cursor to be used when over the sash.# ------------------------------------------------------------------configbody iwidgets::Panedwindow::sashcursor { if {$_initialized} { for {set i 1} {$i < [llength $_activePanes]} {incr i} { $itk_component(sash$i) configure -cursor $itk_option(-sashcursor) } }}# ------------------------------------------------------------------# OPTION: -sashwidth## Specifies the width of the sash.# ------------------------------------------------------------------configbody iwidgets::Panedwindow::sashwidth { set pixels [winfo pixels $itk_component(hull) \ $itk_option(-sashwidth)] set itk_option(-sashwidth) $pixels if {$_initialized} { for {set i 1} {$i < [llength $_activePanes]} {incr i} { $itk_component(sash$i) configure \ -width $itk_option(-sashwidth) } }}# ------------------------------------------------------------------# OPTION: -sashheight## Specifies the height of the sash,# ------------------------------------------------------------------configbody iwidgets::Panedwindow::sashheight { set pixels [winfo pixels $itk_component(hull) \ $itk_option(-sashheight)] set itk_option(-sashheight) $pixels if {$_initialized} { for {set i 1} {$i < [llength $_activePanes]} {incr i} { $itk_component(sash$i) configure \ -height $itk_option(-sashheight) } }}# ------------------------------------------------------------------# OPTION: -thickness## Specifies the thickness of the separators. It sets the width and# height of the separator to the thickness value and the borderwidth# to half the thickness.# ------------------------------------------------------------------configbody iwidgets::Panedwindow::thickness { set pixels [winfo pixels $itk_component(hull) \ $itk_option(-thickness)] set itk_option(-thickness) $pixels if {$_initialized} { for {set i 1} {$i < [llength $_activePanes]} {incr i} { $itk_component(separator$i) configure \ -height $itk_option(-thickness) $itk_component(separator$i) configure \ -width $itk_option(-thickness) $itk_component(separator$i) configure \ -borderwidth [expr $itk_option(-thickness) / 2] } for {set i 1} {$i < [llength $_activePanes]} {incr i} { _placeSash $i } }}# ------------------------------------------------------------------# OPTION: -sashindent## Specifies the placement of the sash along the panes. A positive# value causes the sash to be offset from the near (left/top) side# of the pane, and a negative value causes the sash to be offset from# the far (right/bottom) side. If the offset is greater than the # width, then the sash is placed flush against the side. # ------------------------------------------------------------------configbody iwidgets::Panedwindow::sashindent { set pixels [winfo pixels $itk_component(hull) \ $itk_option(-sashindent)] set itk_option(-sashindent) $pixels if {$_initialized} { for {set i 1} {$i < [llength $_activePanes]} {incr i} { _placeSash $i } }}# ------------------------------------------------------------------# METHODS# ------------------------------------------------------------------# ------------------------------------------------------------------# METHOD: index index## Searches the panes in the paned window for the one with the # requested tag, numerical index, or keyword "end". Returns the pane's # numerical index if found, otherwise error.# ------------------------------------------------------------------ body iwidgets::Panedwindow::index {index} { if {[llength $_panes] > 0} { if {[regexp {(^[0-9]+$)} $index]} { if {$index < [llength $_panes]} { return $index } else { error "Panedwindow index \"$index\" is out of range" } } elseif {$index == "end"} { return [expr [llength $_panes] - 1] } else { if {[set idx [lsearch $_panes $index]] != -1} { return $idx } error "bad Panedwindow index \"$index\": must be number, end,\ or pattern" } } else { error "Panedwindow \"$itk_component(hull)\" has no panes" }}# ------------------------------------------------------------------# METHOD: childsite ?index?## Given an index return the specifc childsite path name. Invoked # without an index return a list of all the child site panes. The # list is ordered from the near side (left/top).# ------------------------------------------------------------------body iwidgets::Panedwindow::childsite {args} { if {! $_initialized} { set _initialized 1 reset } if {[llength $args] == 0} { set children {} foreach pane $_panes { lappend children [$itk_component($pane) childSite] } return $children } else { set index [index [lindex $args 0]] return [$itk_component([lindex $_panes $index]) childSite] }}# ------------------------------------------------------------------# METHOD: fraction percentage percentage ?percentage ...?## Sets the visible percentage of the panes. Specifies a list of# percentages which are applied to the currently visible panes from # the near side (left/top). The number of percentages must be equal # to the current number of visible (mapped) panes and add up to 100.# ------------------------------------------------------------------body iwidgets::Panedwindow::fraction {percentage1 percentage2 args} { set args [linsert $args 0 $percentage1 $percentage2] if {[llength $args] == [llength $_activePanes]} { set sum 0 for {set i 0} {$i < [llength $args]} {incr i} { set sum [expr $sum + [lindex $args $i]] } if {$sum == 100} { set perc 0.0 for {set i 0} {$i < [llength $_activePanes]} {incr i} { set _frac($i) $perc set perc [expr $perc + [expr [lindex $args $i] / 100.0]] } set _frac($i) 1.0 if {[winfo ismapped $itk_component(hull)]} { _placePanes } } else { error "bad fraction arguments \"$args\": they should add\ up to 100" } } else { error "wrong # args: should be \"$itk_component(hull)\ fraction percentage percentage ?percentage ...?\",\ where the number of percentages is\ [llength $_activePanes] and equal 100" }}# ------------------------------------------------------------------# METHOD: add tag ?option value option value ...?## Add a new pane to the paned window to the far (right/bottom) side.# The method takes additional options which are passed on to the # pane constructor. These include -margin, and -minimum. The path # of the pane is returned.# ------------------------------------------------------------------body iwidgets::Panedwindow::add {tag args} { # # Create panes. # itk_component add $tag { eval iwidgets::Pane $itk_interior.pane[incr _unique] $args } { keep -background -cursor } lappend _panes $tag lappend _activePanes $tag reset return $itk_component($tag)}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -