📄 panedwindow.itk
字号:
# ------------------------------------------------------------------# METHOD: insert index tag ?option value option value ...?## Insert the specified pane in the paned window just before the one # given by index. Any additional options which are passed on to the # pane constructor. These include -margin, -minimum. The path of # the pane is returned.# ------------------------------------------------------------------body iwidgets::Panedwindow::insert {index tag args} { # # Create panes. # itk_component add $tag { eval iwidgets::Pane $itk_interior.pane[incr _unique] $args } { keep -background -cursor } set index [index $index] set _panes [linsert $_panes $index $tag] lappend _activePanes $tag reset return $itk_component($tag)}# ------------------------------------------------------------------# METHOD: delete index## Delete the specified pane.# ------------------------------------------------------------------body iwidgets::Panedwindow::delete {index} { set index [index $index] set tag [lindex $_panes $index] destroy $itk_component($tag) set _panes [lreplace $_panes $index $index] reset}# ------------------------------------------------------------------# METHOD: hide index## Remove the specified pane from the paned window. # ------------------------------------------------------------------body iwidgets::Panedwindow::hide {index} { set index [index $index] set tag [lindex $_panes $index] if {[set idx [lsearch -exact $_activePanes $tag]] != -1} { set _activePanes [lreplace $_activePanes $idx $idx] } reset} # ------------------------------------------------------------------# METHOD: show index## Display the specified pane in the paned window.# ------------------------------------------------------------------body iwidgets::Panedwindow::show {index} { set index [index $index] set tag [lindex $_panes $index] if {[lsearch -exact $_activePanes $tag] == -1} { lappend _activePanes $tag } reset} # ------------------------------------------------------------------# METHOD: paneconfigure index ?option? ?value option value ...?## Configure a specified pane. This method allows configuration of# panes from the Panedwindow level. The options may have any of the # values accepted by the add method.# ------------------------------------------------------------------body iwidgets::Panedwindow::paneconfigure {index args} { set index [index $index] set tag [lindex $_panes $index] return [uplevel $itk_component($tag) configure $args]}# ------------------------------------------------------------------# METHOD: reset## Redisplay the panes based on the default percentages of the panes.# ------------------------------------------------------------------body iwidgets::Panedwindow::reset {} { if {$_initialized && [llength $_panes]} { _setActivePanes _setFracArray _makeSashes _placePanes }}# ------------------------------------------------------------------# PROTECTED METHOD: _pwConfigureEventHandler## Performs operations necessary following a configure event. This# includes placing the panes.# ------------------------------------------------------------------body iwidgets::Panedwindow::_pwConfigureEventHandler {width height} { set _width $width set _height $height if {$_initialized} { _placePanes } else { set _initialized 1 reset }}# ------------------------------------------------------------------# PROTECTED METHOD: _startGrip where num## Starts the sash drag and drop operation. At the start of the drag# operation all the information is known as for the upper and lower# limits for sash movement. The calculation is made at this time and# stored in protected variables for later access during the drag# handling routines.# ------------------------------------------------------------------body iwidgets::Panedwindow::_startGrip {where num} { if {$itk_option(-orient) == "horizontal"} { set _dimension $_height } else { set _dimension $_width } set _minsashmoved $num set _maxsashmoved $num set totMinHeight 0 set cnt [llength $_activePanes] set _sashloc(0) 0 set _pixels($cnt) [expr int($_dimension)] for {set i 0} {$i < $cnt} {incr i} { set _pixels($i) [expr int($_frac($i) * $_dimension)] set margaft [$itk_component([lindex $_activePanes $i]) cget -margin] set minaft [$itk_component([lindex $_activePanes $i]) cget -minimum] set _minheight($i) [expr $minaft + (2 * $margaft)] incr totMinHeight $_minheight($i) } set _dragging [expr $_dimension > $totMinHeight] grab $itk_component(sash$num) raise $itk_component(separator$num) raise $itk_component(sash$num) $itk_component(sash$num) configure -relief sunken}# ------------------------------------------------------------------# PROTECTED METHOD: _endGrip where num## Ends the sash drag and drop operation.# ------------------------------------------------------------------body iwidgets::Panedwindow::_endGrip {where num} { $itk_component(sash$num) configure -relief raised grab release $itk_component(sash$num) if {$_dragging} { _calcFraction [expr $_sashloc($num) + $where] $num _placePanes [expr $_minsashmoved - 1] $_maxsashmoved set _dragging 0 }}# ------------------------------------------------------------------# PROTECTED METHOD: _configGrip where num## Configure action for sash.# ------------------------------------------------------------------body iwidgets::Panedwindow::_configGrip {where num} { set _sashloc($num) $where}# ------------------------------------------------------------------# PROTECTED METHOD: _handleGrip where num## Motion action for sash.# ------------------------------------------------------------------body iwidgets::Panedwindow::_handleGrip {where num} { if {$_dragging} { _moveSash [expr $where + $_sashloc($num)] $num incr _movecount if {$_movecount>4} { set _movecount 0 update idletasks } }}# ------------------------------------------------------------------# PROTECTED METHOD: _moveSash where num## Move the sash to the absolute pixel location# ------------------------------------------------------------------body iwidgets::Panedwindow::_moveSash {where num} { set _minsashmoved [expr ($_minsashmoved<$num)?$_minsashmoved:$num] set _maxsashmoved [expr ($_maxsashmoved>$num)?$_maxsashmoved:$num] set oldfrac $_frac($num) _calcFraction $where $num if {$_frac($num)!=$oldfrac} { _placeSash $num }}# ------------------------------------------------------------------# PRIVATE METHOD: _setFracArray## Calculates the percentages for the fraction array which lists the# percentages for each pane.# ------------------------------------------------------------------body iwidgets::Panedwindow::_setFracArray {} { set perc 0.0 if {[llength $_activePanes] != 0} { set percIncr [expr 1.0 / [llength $_activePanes]] } for {set i 0} {$i < [llength $_activePanes]} {incr i} { set _frac($i) $perc set perc [expr $perc + $percIncr] } set _frac($i) 1.0}# ------------------------------------------------------------------# PRIVATE METHOD: _setActivePanes## Resets the active pane list.# ------------------------------------------------------------------body iwidgets::Panedwindow::_setActivePanes {} { set _prevActivePanes $_activePanes set _activePanes {} foreach pane $_panes { if {[lsearch -exact $_prevActivePanes $pane] != -1} { lappend _activePanes $pane } }}# ------------------------------------------------------------------# PRIVATE METHOD: _calcFraction where num## Determines the fraction for the sash. Make sure the fraction does# not go past the minimum for the pane on each side of the separator.# ------------------------------------------------------------------body iwidgets::Panedwindow::_calcFraction {where num} { set _lowerlimit \ [expr $_pixels([expr $num - 1]) + $_minheight([expr $num - 1])] set _upperlimit \ [expr $_pixels([expr $num + 1]) - $_minheight($num)] set dir [expr $where - $_pixels($num)] if {$where < $_lowerlimit && $dir <= 0} { if {$num == 1} { set _pixels($num) $_lowerlimit } { _moveSash [expr $where - $_minheight([expr $num - 1])] [expr $num -1] set _pixels($num) \ [expr $_pixels([expr $num - 1]) + $_minheight([expr $num - 1])] } } elseif {$where > $_upperlimit && $dir >= 0} { if {[expr $num + 1] == [llength $_activePanes]} { set _pixels($num) $_upperlimit } { _moveSash [expr $where + $_minheight($num)] [expr $num +1] set _pixels($num) \ [expr $_pixels([expr $num + 1]) - $_minheight($num)] } } else { set _pixels($num) $where } set _frac($num) [expr $_pixels($num).0 / $_dimension]}# ------------------------------------------------------------------# PRIVATE METHOD: _makeSashes## Removes any previous sashes and separators and creates new one.# ------------------------------------------------------------------body iwidgets::Panedwindow::_makeSashes {} { # # Remove any existing sashes and separators. # foreach sash $_sashes { destroy $itk_component($sash) } foreach separator $_separators { destroy $itk_component($separator) } set _sashes {} set _separators {} # # Create one less separator and sash than the number of panes. # for {set id 1} {$id < [llength $_activePanes]} {incr id} { itk_component add sash$id { frame $itk_interior.sash$id -relief raised \ -borderwidth $itk_option(-sashborderwidth) \ -cursor $itk_option(-sashcursor) \ -width $itk_option(-sashwidth) \ -height $itk_option(-sashheight) } { keep -background } lappend _sashes sash$id switch $itk_option(-orient) { vertical { bind $itk_component(sash$id) <Button-1> \ [code $this _startGrip %x $id] bind $itk_component(sash$id) <B1-Motion> \ [code $this _handleGrip %x $id] bind $itk_component(sash$id) <B1-ButtonRelease-1> \ [code $this _endGrip %x $id] bind $itk_component(sash$id) <Configure> \ [code $this _configGrip %x $id] } horizontal { bind $itk_component(sash$id) <Button-1> \ [code $this _startGrip %y $id] bind $itk_component(sash$id) <B1-Motion> \ [code $this _handleGrip %y $id] bind $itk_component(sash$id) <B1-ButtonRelease-1> \ [code $this _endGrip %y $id] bind $itk_component(sash$id) <Configure> \ [code $this _configGrip %y $id] } } itk_component add separator$id { frame $itk_interior.separator$id -relief sunken \ -height $itk_option(-thickness) \ -width $itk_option(-thickness) \ -borderwidth [expr $itk_option(-thickness) / 2] } { keep -background -cursor } lappend _separators separator$id }}# ------------------------------------------------------------------# PRIVATE METHOD: _placeSash i## Places the position of the sash and separator.# ------------------------------------------------------------------body iwidgets::Panedwindow::_placeSash {i} { if {$itk_option(-orient) == "horizontal"} { place $itk_component(separator$i) -in $itk_component(hull) \ -x 0 -relwidth 1 -rely $_frac($i) -anchor w \ -height $itk_option(-thickness) if {$itk_option(-sashindent) < 0} { set sashPos [expr $_width + $itk_option(-sashindent)] set sashAnchor e } else { set sashPos $itk_option(-sashindent) set sashAnchor w } place $itk_component(sash$i) -in $itk_component(hull) \ -x $sashPos -rely $_frac($i) -anchor $sashAnchor } else { place $itk_component(separator$i) -in $itk_component(hull) \ -y 0 -relheight 1 -relx $_frac($i) -anchor n \ -width $itk_option(-thickness) if {$itk_option(-sashindent) < 0} { set sashPos [expr $_height + $itk_option(-sashindent)] set sashAnchor s } else { set sashPos $itk_option(-sashindent) set sashAnchor n } place $itk_component(sash$i) -in $itk_component(hull) \ -y $sashPos -relx $_frac($i) -anchor $sashAnchor }}# ------------------------------------------------------------------# PRIVATE METHOD: _placePanes## Resets the panes of the window following movement of the sash.# ------------------------------------------------------------------body iwidgets::Panedwindow::_placePanes {{start 0} {end end}} { if {$end=="end"} { set end [expr [llength $_activePanes] - 1] } set _updatePanes [lrange $_activePanes $start $end] if {$_updatePanes == $_activePanes} { set _forgetPanes $_panes } { set _forgetPanes $_updatePanes } foreach pane $_forgetPanes { place forget $itk_component($pane) } if {$itk_option(-orient) == "horizontal"} { set i $start foreach pane $_updatePanes { place $itk_component($pane) -in $itk_component(hull) \ -x 0 -rely $_frac($i) -relwidth 1 \ -relheight [expr $_frac([expr $i + 1]) - $_frac($i)] incr i } } else { set i $start foreach pane $_updatePanes { place $itk_component($pane) -in $itk_component(hull) \ -y 0 -relx $_frac($i) -relheight 1 \ -relwidth [expr $_frac([expr $i + 1]) - $_frac($i)] incr i } } for {set i [expr $start+1]} {$i <= $end} {incr i} { if {[array names itk_component separator$i] != ""} { _placeSash $i raise $itk_component(separator$i) raise $itk_component(sash$i) } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -