📄 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,v 1.7 2001/09/06 15:12:46 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.# ======================================================================## Usual options.#itk::usual Panedwindow { keep -background -cursor -sashcursor}# ------------------------------------------------------------------# PANEDWINDOW# ------------------------------------------------------------------itcl::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 itk_option define -showhandle showHandle ShowHandle 1 public method index {index} public method childsite {args} public method fraction {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. private variable _relief ;# relief for -showhandle}## 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# ------------------------------------------------------------------itcl::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> [itcl::code $this _pwConfigureEventHandler %w %h] bindtags $itk_component(hull) \ [linsert [bindtags $itk_component(hull)] 0 pw-config-$this] array set _relief {0 sunken 1 raised} 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.# ------------------------------------------------------------------itcl::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> \ [itcl::code $this _startGrip %x $i] bind $itk_component(sash$i) <B1-Motion> \ [itcl::code $this _handleGrip %x $i] bind $itk_component(sash$i) <B1-ButtonRelease-1> \ [itcl::code $this _endGrip %x $i] bind $itk_component(sash$i) <Configure> \ [itcl::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> \ [itcl::code $this _startGrip %y $i] bind $itk_component(sash$i) <B1-Motion> \ [itcl::code $this _handleGrip %y $i] bind $itk_component(sash$i) <B1-ButtonRelease-1> \ [itcl::code $this _endGrip %y $i] bind $itk_component(sash$i) <Configure> \ [itcl::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.# ------------------------------------------------------------------itcl::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.# ------------------------------------------------------------------itcl::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.# ------------------------------------------------------------------itcl::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,# ------------------------------------------------------------------itcl::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: -showhandle## Specifies whether or not to show the sash handle. If not, then the# whole separator becomes the handle. Valid values are 0 or 1.# ------------------------------------------------------------------itcl::configbody iwidgets::Panedwindow::showhandle { switch $itk_option(-showhandle) { 0 - 1 { # Update the sashes. _makeSashes _placePanes } default { error "Invalid option for -showhandle: $itk_option(-showhandle).\ Must be 1 or 0." } }}# ------------------------------------------------------------------# 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.# ------------------------------------------------------------------itcl::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 } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -