📄 tabset.itk
字号:
}}# ----------------------------------------------------------------------# OPTION -disabledforeground# ----------------------------------------------------------------------configbody iwidgets::Tabset::disabledforeground { if {$itk_option(-disabledforeground) != {}} { _tabConfigure \ -disabledforeground $itk_option(-disabledforeground) }}# ----------------------------------------------------------------------# OPTION -foreground## Sets the foreground label color of UNSELECTED tabs# ----------------------------------------------------------------------configbody iwidgets::Tabset::foreground { _tabConfigure -foreground $itk_option(-foreground)}# ----------------------------------------------------------------------# OPTION -background## Sets the background color of UNSELECTED tabs# ----------------------------------------------------------------------configbody iwidgets::Tabset::background { if {$itk_option(-background) != {}} { _tabConfigure -background $itk_option(-background) } else { _tabConfigure -background \ [$itk_component(canvas) cget -background] }}# ----------------------------------------------------------------------# OPTION -selectforeground## Sets the foreground label color of SELECTED tabs# ----------------------------------------------------------------------configbody iwidgets::Tabset::selectforeground { _tabConfigure -selectforeground $itk_option(-selectforeground)}# ----------------------------------------------------------------------# OPTION -backdrop## Sets the background color of the Tabset backdrop (behind the tabs)# ----------------------------------------------------------------------configbody iwidgets::Tabset::backdrop { if {$itk_option(-backdrop) != {}} { $itk_component(canvas) configure \ -background $itk_option(-backdrop) }}# ----------------------------------------------------------------------# OPTION -selectbackground## Sets the background color of SELECTED tabs# ----------------------------------------------------------------------configbody iwidgets::Tabset::selectbackground { if {$itk_option(-selectbackground) != {}} { } else { #set _selectBackground \ [$itk_component(canvas) cget -background] } _tabConfigure -selectbackground $itk_option(-selectbackground)}# ----------------------------------------------------------------------# OPTION -command## The command to invoke when a tab is hit.# ----------------------------------------------------------------------configbody iwidgets::Tabset::command { if {$itk_option(-command) != {}} { set _cmdStr $itk_option(-command) }}# ----------------------------------------------------------------------# METHOD: add ?option value...?## Creates a tab and appends it to the list of tabs.# processes tabconfigure for the tab added.# ----------------------------------------------------------------------body iwidgets::Tabset::add {args} { set tabName [eval _createTab $args] lappend _tabs $tabName _relayoutTabs return $tabName}# ----------------------------------------------------------------------# METHOD: configure ?option? ?value option value...?## Acts as an addendum to the itk::Widget::configure method.## Checks the _relayout flag to see if after configures are done# we need to relayout the tabs.## _skipRelayout is set in the MB2 scroll methods, to avoid constant# relayout of tabs while dragging the mouse.# ----------------------------------------------------------------------body iwidgets::Tabset::configure {args} { set result [eval itk::Archetype::configure $args] _configRelayout return $result}body iwidgets::Tabset::_configRelayout {} { # then relayout tabs if necessary if { $_relayout } { if { $_skipRelayout } { } else { _relayoutTabs } set _relayout false }}# ----------------------------------------------------------------------# METHOD: delete index1 ?index2?## Deletes a tab or range of tabs from the tabset# ----------------------------------------------------------------------body iwidgets::Tabset::delete {args} { if { $_tabs == {} } { error "can't delete tabs,\ no tabs in the tabset named $itk_component(hull)" } set len [llength $args] switch $len { 0 { error "wrong # args: should be\ \"$itk_component(hull) delete index1 ?index2?\"" } 1 { set fromTab [index [lindex $args 0]] if { $fromTab == -1 } { error "bad value for index1:\ [lindex $args 0] in call to delete" } set toTab $fromTab _deleteTabs $fromTab $toTab } 2 { set fromTab [index [lindex $args 0]] if { $fromTab == -1 } { error "bad value for index1:\ [lindex $args 0] in call to delete" } set toTab [index [lindex $args 1]] if { $toTab == -1 } { error "bad value for index2:\ [lindex $args 1] in call to delete" } _deleteTabs $fromTab $toTab } default { error "wrong # args: should be\ \"$itk_component(hull) delete index1 ?index2?\"" } }}# ----------------------------------------------------------------------# METHOD: index index## Given an index identifier returns the numeric index of the tab# ----------------------------------------------------------------------body iwidgets::Tabset::index {index} { return [_index $_tabs $index $_currTab]}# ----------------------------------------------------------------------# METHOD: insert index ?option value...?## Inserts a tab before a index. The before tab may# be specified as a label or a tab position.# ----------------------------------------------------------------------body iwidgets::Tabset::insert {index args} { if { $_tabs == {} } { error "no tab to insert before,\ tabset '$itk_component(hull)' is empty" } # get the tab set tab [index $index] # catch bad value for before tab. if { $tab < 0 || $tab >= [llength $_tabs] } { error "bad value $tab for index:\ should be between 0 and [expr [llength $_tabs] - 1]" } # create the new tab and get its name... set tabName [eval _createTab $args] # grab the name of the tab currently selected. (to keep in sync) set currTabName [lindex $_tabs $_currTab] # insert tabName before $tab set _tabs [linsert $_tabs $tab $tabName] # keep the _currTab in sync with the insert. set _currTab [lsearch -exact $_tabs $currTabName] _relayoutTabs return $tabName}# ----------------------------------------------------------------------# METHOD: prev## Selects the prev tab. Wraps at first back to last tab.# ----------------------------------------------------------------------body iwidgets::Tabset::prev {} { if { $_tabs == {} } { error "can't goto previous tab,\ no tabs in the tabset: $itk_component(hull)" } # bump to the previous tab and wrap if necessary set prev [expr $_currTab - 1] if { $prev < 0 } { set prev [expr [llength $_tabs] - 1] } select $prev }# ----------------------------------------------------------------------# METHOD: next## Selects the next tab. Wraps at last back to first tab.# ----------------------------------------------------------------------body iwidgets::Tabset::next {} { if { $_tabs == {} } { error "can't goto next tab,\ no tabs in the tabset: $itk_component(hull)" } # bump to the next tab and wrap if necessary set next [expr $_currTab + 1] if { $next >= [llength $_tabs] } { set next 0 } select $next}# ----------------------------------------------------------------------# METHOD: select index## Select a tab by index## Lowers the last _currTab if it existed.# Then raises the new one if it exists.## Returns numeric index of selection, -1 if failed.# -------------------------------------------------------------body iwidgets::Tabset::select {index} { if { $_tabs == {} } { error "can't activate a tab,\ no tabs in the tabset: $itk_component(hull)" } # if there is not current selection just ignore trying this selection if { $index == "select" && $_currTab == -1 } { return -1 } # is selection request in range ? set reqTab [index $index] if { $reqTab == -1 } { error "bad value $index for index:\ should be from 0 to [expr [llength $_tabs] - 1]" } # If already selected then ignore and return... if { $reqTab == $_currTab } { return $reqTab } # ---- Deselect if { $_currTab != -1 } { set currTabName [lindex $_tabs $_currTab] $currTabName deselect # handle different orientations... if { $itk_option(-tabpos) == "n" || $itk_option(-tabpos) == "s"} { $currTabName configure -top $_deselectedTop } else { $currTabName configure -left $_deselectedLeft } } # get the stacking order correct... foreach tab $_tabs { $tab lower } # set this now so that the -command cmd can do an 'index select' # to operate on this tab. set _currTab $reqTab # ---- Select set reqTabName [lindex $_tabs $reqTab] $reqTabName select if { $itk_option(-tabpos) == "n" || $itk_option(-tabpos) == "s"} { $reqTabName configure -top $_selectedTop } else { $reqTabName configure -left $_selectedLeft } set _currTab $reqTab # invoke any user command string, appended with tab index number if { $_cmdStr != {} } { set newCmd $_cmdStr eval [lappend newCmd $reqTab] } return $reqTab}# ----------------------------------------------------------------------# METHOD: tabcget index ?option? ## Returns the value for the option setting of the tab at index $index.# ----------------------------------------------------------------------body iwidgets::Tabset::tabcget {index args} { return [lindex [eval tabconfigure $index $args] 2]}# ----------------------------------------------------------------------# METHOD: tabconfigure index ?option? ?value option value?## tabconfigure index : returns configuration list# tabconfigure index -option : returns option values# tabconfigure index ?option value option value ...? sets options# and returns empty string.## Performs configure on a given tab denoted by index.## Index may be a tab number or a pattern matching the label# associated with a tab.# ----------------------------------------------------------------------body iwidgets::Tabset::tabconfigure {index args} { # convert index to numeric set tab [index $index] if { $tab == -1 } { error "bad index value:\ $index for $itk_component(hull) tabconfigure" } set tabName [lindex $_tabs $tab] set len [llength $args] switch $len { 0 { return [eval $tabName configure] } 1 { return [eval $tabName configure $args] } default { eval $tabName configure $args _relayoutTabs select select } } return ""}# ----------------------------------------------------------------------# PROTECTED METHOD: _selectName## internal method to allow selection by internal tab name # rather than index. This is used by the bind methods# ----------------------------------------------------------------------body iwidgets::Tabset::_selectName {tabName} { # if the tab is disabled, then ignore this selection... if { [$tabName cget -state] == "disabled" } { return } set tab [lsearch -exact $_tabs $tabName] select $tab}# ----------------------------------------------------------------------# PRIVATE METHOD: _createTab## Creates a tab, using unique tab naming, propagates background# and keeps unique id up to date.# ----------------------------------------------------------------------body iwidgets::Tabset::_createTab {args} { # # create an internal name for the tab: tab0, tab1, etc. # these are one-up numbers they do not # correspond to the position the tab is located in. # set tabName $this-tab$_uniqueID switch $itk_option(-tabpos) { n { set invert true set orient horizontal set x 0 set y [expr $_margin + 1]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -