📄 tabset.itk
字号:
} s { set invert false set orient horizontal set x 0 set y 0 } w { set invert false set orient vertical set x 0 set y 0 } e { set invert true set orient vertical set x [expr $_margin + 1] set y 0 } default { error "bad anchor position\ \"$itk_option(-tabpos)\" must be n, s, e, or w" } } eval iwidgets::Tab $tabName $itk_component(canvas) \ -left $x \ -top $y \ -font [list $itk_option(-font)] \ -background $itk_option(-background) \ -foreground $itk_option(-foreground) \ -selectforeground $itk_option(-selectforeground) \ -disabledforeground $itk_option(-disabledforeground) \ -selectbackground $itk_option(-selectbackground) \ -angle $itk_option(-angle) \ -padx $itk_option(-padx) \ -pady $itk_option(-pady) \ -bevelamount $itk_option(-bevelamount) \ -state $itk_option(-state) \ -tabborders $itk_option(-tabborders) \ -invert $invert \ -orient $orient \ $args $tabName lower $itk_component(canvas) \ bind $tabName <Button-1> [code $this _selectName $tabName] incr _uniqueID return $tabName}# ----------------------------------------------------------------------# PRIVATE METHOD: _deleteTabs## Deletes tabs from $fromTab to $toTab.## Operates in two passes, destroys all the widgets# Then removes the pathName from the tab list## Also keeps the current selection in bounds.# ----------------------------------------------------------------------body iwidgets::Tabset::_deleteTabs {fromTab toTab} { for { set tab $fromTab } { $tab <= $toTab } { incr tab } { set tabName [lindex $_tabs $tab] # unbind Button-1 from this window name $itk_component(canvas) bind $tabName <Button-1> {} # Destroy the Tab class... itcl::delete object $tabName } # physically remove the tab set _tabs [lreplace $_tabs $fromTab $toTab] # If we deleted a selected tab set our selection to none if { $_currTab >= $fromTab && $_currTab <= $toTab } { set _currTab -1 _drawBevelBorder } # make sure _currTab stays in sync with new numbering... if { $_tabs == {} } { # if deleted only remaining tab, # reset current tab to undefined set _currTab -1 # or if the current tab was the last tab, it needs come back } elseif { $_currTab >= [llength $_tabs] } { incr _currTab -1 if { $_currTab < 0 } { # but only to zero set _currTab 0 } } _relayoutTabs}# ----------------------------------------------------------------------# PRIVATE METHOD: _index## pathList : list of path names to search thru if index is a label# index : either number, 'select', 'end', or pattern# select : current selection## _index takes takes the value $index converts it to# a numeric identifier. If the value is not already# an integer it looks it up in the $pathList array.# If it fails it returns -1# ----------------------------------------------------------------------body iwidgets::Tabset::_index {pathList index select} { switch $index { select { set number $select } end { set number [expr [llength $pathList] -1] } default { # is it an number already? if { [regexp {^[0-9]+$} $index] } { set number $index if { $number < 0 || $number >= [llength $pathList] } { set number -1 } # otherwise it is a label } else { # look thru the pathList of pathNames and # get each label and compare with index. # if we get a match then set number to postion in $pathList # and break out. # otherwise number is still -1 set i 0 set number -1 foreach pathName $pathList { set label [$pathName cget -label] if { $label == $index } { set number $i break } incr i } } } } return $number}# ----------------------------------------------------------------------# PRIVATE METHOD: _tabConfigure# ----------------------------------------------------------------------body iwidgets::Tabset::_tabConfigure {args} { foreach tab $_tabs { eval $tab configure $args } set _relayout true if { $_tabs != {} } { select select }}# ----------------------------------------------------------------------# PRIVATE METHOD: _relayoutTabs# # relays out the tabs with correct spacing...# ----------------------------------------------------------------------body iwidgets::Tabset::_relayoutTabs {} { if { [llength $_tabs] == 0 } { return } # get the max width for fixed width tabs... set maxWidth 0 foreach tab $_tabs { set width [$tab labelwidth] if { $width > $maxWidth } { set maxWidth $width } } # get the max height for fixed height tabs... set maxHeight 0 foreach tab $_tabs { set height [$tab labelheight] if { $height > $maxHeight } { set maxHeight $height } } # get curr tab's name set currTabName [lindex $_tabs $_currTab] # Start with our margin offset in pixels... set tabStart $_start if { $itk_option(-raiseselect) } { set raiseAmt 2 } else { set raiseAmt 0 } # # Depending on the tab layout: n, s, e, or w place the tabs # according to orientation, raise, margins, etc. # switch $itk_option(-tabpos) { n { set _selectedTop [expr $_margin + 1] set _deselectedTop [expr $_selectedTop + $raiseAmt] if { $itk_option(-equaltabs) } { set tabWidth $maxWidth } else { set tabWidth 0 } foreach tab $_tabs { if { $tab == $currTabName } { $tab configure -left $tabStart -top $_selectedTop \ -height $maxHeight -width $tabWidth -anchor c } else { $tab configure -left $tabStart -top $_deselectedTop \ -height $maxHeight -width $tabWidth -anchor c } set tabStart [expr $tabStart + [_calcNextTabOffset $tab]] } } s { set _selectedTop 0 set _deselectedTop [expr $_selectedTop - $raiseAmt] if { $itk_option(-equaltabs) } { set tabWidth $maxWidth } else { set tabWidth 0 } foreach tab $_tabs { if { $tab == $currTabName } { $tab configure -left $tabStart -top $_selectedTop \ -height $maxHeight -width $tabWidth -anchor c } else { $tab configure -left $tabStart -top $_deselectedTop \ -height $maxHeight -width $tabWidth -anchor c } set tabStart [expr $tabStart + [_calcNextTabOffset $tab]] } } w { set _selectedLeft [expr $_margin + 1] set _deselectedLeft [expr $_selectedLeft + $raiseAmt] if { $itk_option(-equaltabs) } { set tabHeight $maxHeight } else { set tabHeight 0 } foreach tab $_tabs { # selected if { $tab == $currTabName } { $tab configure -top $tabStart -left $_selectedLeft \ -height $tabHeight -width $maxWidth -anchor e # deselected } else { $tab configure -top $tabStart -left $_deselectedLeft \ -height $tabHeight -width $maxWidth -anchor e } set tabStart [expr $tabStart + [_calcNextTabOffset $tab]] } } e { set _selectedLeft 0 set _deselectedLeft [expr $_selectedLeft - $raiseAmt] if { $itk_option(-equaltabs) } { set tabHeight $maxHeight } else { set tabHeight 0 } foreach tab $_tabs { # selected if { $tab == $currTabName } { $tab configure -top $tabStart -left $_selectedLeft \ -height $tabHeight -width $maxWidth -anchor w # deselected } else { $tab configure -top $tabStart -left $_deselectedLeft \ -height $tabHeight -width $maxWidth -anchor w } set tabStart [expr $tabStart + [_calcNextTabOffset $tab]] } } default { error "bad anchor position\ \"$itk_option(-tabpos)\" must be n, s, e, or w" } } # put border on & calc our new canvas size... _drawBevelBorder _recalcCanvasGeom }# ----------------------------------------------------------------------# PRIVATE METHOD: _drawBevelBorder# # draws the bevel border along tab edge (below selected tab)# ----------------------------------------------------------------------body iwidgets::Tabset::_drawBevelBorder {} { $itk_component(canvas) delete bevelBorder switch $itk_option(-tabpos) { n { $itk_component(canvas) create line \ 0 [expr $_canvasHeight - 1] \ $_canvasWidth [expr $_canvasHeight - 1] \ -fill [iwidgets::colors::topShadow $itk_option(-selectbackground)] \ -tags bevelBorder $itk_component(canvas) create line \ 0 $_canvasHeight \ $_canvasWidth $_canvasHeight \ -fill [iwidgets::colors::topShadow $itk_option(-selectbackground)] \ -tags bevelBorder } s { $itk_component(canvas) create line \ 0 0 \ $_canvasWidth 0 \ -fill [iwidgets::colors::bottomShadow $itk_option(-selectbackground)] \ -tags bevelBorder $itk_component(canvas) create line \ 0 1 \ $_canvasWidth 1 \ -fill black \ -tags bevelBorder } w { $itk_component(canvas) create line \ $_canvasWidth 0 \ $_canvasWidth [expr $_canvasHeight - 1] \ -fill [iwidgets::colors::topShadow $itk_option(-selectbackground)] \ -tags bevelBorder $itk_component(canvas) create line \ [expr $_canvasWidth - 1] 0 \ [expr $_canvasWidth - 1] [expr $_canvasHeight - 1] \ -fill [iwidgets::colors::topShadow $itk_option(-selectbackground)] \ -tags bevelBorder } e { $itk_component(canvas) create line \ 0 0 \ 0 [expr $_canvasHeight - 1] \ -fill black \ -tags bevelBorder $itk_component(canvas) create line \ 1 0 \ 1 [expr $_canvasHeight - 1] \ -fill [iwidgets::colors::bottomShadow $itk_option(-selectbackground)] \ -tags bevelBorder } } $itk_component(canvas) raise bevelBorder if { $_currTab != -1 } { set currTabName [lindex $_tabs $_currTab] $currTabName raise }}# ----------------------------------------------------------------------# PRIVATE METHOD: _calcNextTabOffset# # given $tabName, determines the offset in pixels to place# the next tab's start edge at.# ----------------------------------------------------------------------body iwidgets::Tabset::_calcNextTabOffset {tabName} { if { $_gap == "overlap" } { return [$tabName offset] } else { return [expr [$tabName majordim] + $_gap] }}# ----------------------------------------------------------------------# PRIVATE METHOD: _tabBounds# # calculates the bounding box that will completely enclose # all the tabs.# ----------------------------------------------------------------------body iwidgets::Tabset::_tabBounds {} { set bbox { 100000 100000 -10000 -10000 } foreach tab $_tabs { set tabBBox [$tab bbox] # if this left is less use it if { [lindex $tabBBox 0] < [lindex $bbox 0] } { set bbox [lreplace $bbox 0 0 [lindex $tabBBox 0]] } # if this top is greater use it if { [lindex $tabBBox 1] < [lindex $bbox 1] } { set bbox [lreplace $bbox 1 1 [lindex $tabBBox 1]] } # if this right is less use it if { [lindex $tabBBox 2] > [lindex $bbox 2] } { set bbox [lreplace $bbox 2 2 [lindex $tabBBox 2]] } # if this bottom is greater use it if { [lindex $tabBBox 3] > [lindex $bbox 3] } { set bbox [lreplace $bbox 3 3 [lindex $tabBBox 3]] }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -