#============================================================================== # Contains public and private procedures used in tablelist bindings. # # Structure of the module: # - Public helper procedures # - Binding tag Tablelist # - Binding tag TablelistWindow # - Binding tag TablelistBody # - Binding tags TablelistLabel, TablelistSubLabel, and TablelistArrow # # Copyright (c) 2000-2006 Csaba Nemethi (E-mail: csaba.nemethi@t-online.de) #============================================================================== # # Public helper procedures # ======================== # #------------------------------------------------------------------------------ # tablelist::getTablelistPath # # Gets the path name of the tablelist widget from the path name w of one of its # descendants. It is assumed that all of the ancestors of w exist (but w # itself needn't exist). #------------------------------------------------------------------------------ proc tablelist::getTablelistPath w { return [mwutil::getAncestorByClass $w Tablelist] } #------------------------------------------------------------------------------ # tablelist::convEventFields # # Gets the path name of the tablelist widget and the x and y coordinates # relative to the latter from the path name w of one of its descendants and # from the x and y coordinates relative to the latter. #------------------------------------------------------------------------------ proc tablelist::convEventFields {w x y} { return [mwutil::convEventFields $w $x $y Tablelist] } # # Binding tag Tablelist # ===================== # #------------------------------------------------------------------------------ # tablelist::addActiveTag # # This procedure is invoked when the tablelist widget win gains the keyboard # focus. It adds the "active" tag to the line or cell that displays the active # item or element of the widget in its body text child. #------------------------------------------------------------------------------ proc tablelist::addActiveTag win { upvar ::tablelist::ns${win}::data data set line [expr {$data(activeRow) + 1}] set col $data(activeCol) if {[string compare $data(-selecttype) "row"] == 0} { $data(body) tag add active $line.0 $line.end } elseif {$data(itemCount) > 0 && $data(colCount) > 0 && !$data($col-hide)} { findTabs $win $line $col $col tabIdx1 tabIdx2 $data(body) tag add active $tabIdx1 $tabIdx2+1c } set data(ownsFocus) 1 } #------------------------------------------------------------------------------ # tablelist::removeActiveTag # # This procedure is invoked when the tablelist widget win loses the keyboard # focus. It removes the "active" tag from the body text child of the widget. #------------------------------------------------------------------------------ proc tablelist::removeActiveTag win { upvar ::tablelist::ns${win}::data data $data(body) tag remove active 1.0 end set data(ownsFocus) 0 } #------------------------------------------------------------------------------ # tablelist::updateConfigSpecs # # This procedure handles the virtual event <> by updating the # theme-specific default values of some tablelist configuration options. #------------------------------------------------------------------------------ proc tablelist::updateConfigSpecs win { upvar ::tablelist::ns${win}::data data if {[string compare $tile::currentTheme $data(currentTheme)] == 0 && [string compare $tile::currentTheme "tileqt"] != 0} { return "" } variable themeDefaults variable configSpecs # # Populate the array tmp with values corresponding to the old theme # and the array themeDefaults with values corresponding to the new one # array set tmp $data(themeDefaults) ;# populates the array tmp set tmp(-arrowdisabledcolor) $tmp(-arrowcolor) setThemeDefaults ;# populates the array themeDefaults set themeDefaults(-arrowdisabledcolor) $themeDefaults(-arrowcolor) # # Update the default values in the array configSpecs and # set those configuration options whose values equal the old # theme-specific defaults to the new theme-specific ones # foreach opt {-background -foreground -disabledforeground -stripebackground -selectbackground -selectforeground -selectborderwidth -font -labelbackground -labelforeground -labelfont -labelborderwidth -labelpady -arrowcolor -arrowdisabledcolor -arrowstyle} { lset configSpecs($opt) 3 $themeDefaults($opt) if {[string compare $data($opt) $tmp($opt)] == 0} { doConfig $win $opt $themeDefaults($opt) } } foreach opt {-background -foreground} { doConfig $win $opt $data($opt) ;# sets the bg color of the separators } set data(currentTheme) $tile::currentTheme set data(themeDefaults) [array get themeDefaults] } #------------------------------------------------------------------------------ # tablelist::cleanup # # This procedure is invoked when the tablelist widget win is destroyed. It # executes some cleanup operations. #------------------------------------------------------------------------------ proc tablelist::cleanup win { upvar ::tablelist::ns${win}::data data # # Cancel the execution of all delayed adjustSeps, makeStripes, # stretchColumns, updateColors, updateScrlColOffset, # updateHScrlbar, updateVScrlbar, adjustElidedText, synchronize, # horizAutoScan, doCellConfig, redisplay, and redisplayCol commands # foreach id {sepsId stripesId stretchId colorId offsetId hScrlbarId \ vScrlbarId elidedId syncId afterId reconfigId} { if {[info exists data($id)]} { after cancel $data($id) } } foreach name [array names data *redispId] { after cancel $data($name) } # # If there is a list variable associated with the # widget then remove the trace set on this variable # if {$data(hasListVar) && [info exists $data(-listvariable)]} { upvar #0 $data(-listvariable) var trace vdelete var wu $data(listVarTraceCmd) } namespace delete ::tablelist::ns$win catch {rename ::$win ""} } # # Binding tag TablelistWindow # =========================== # #------------------------------------------------------------------------------ # tablelist::cleanupWindow # # This procedure is invoked when a window aux embedded into a tablelist widget # is destroyed. It invokes the cleanup script associated with the cell # containing the window, if any. #------------------------------------------------------------------------------ proc tablelist::cleanupWindow aux { regexp {^(.+)\.body\.f(k[0-9]+),([0-9]+)$} $aux dummy win key col upvar ::tablelist::ns${win}::data data if {[info exists data($key-$col-windowdestroy)]} { set row [lsearch $data(itemList) "* $key"] uplevel #0 $data($key-$col-windowdestroy) [list $win $row $col $aux.w] } } # # Binding tag TablelistBody # ========================= # #------------------------------------------------------------------------------ # tablelist::defineTablelistBody # # Defines the bindings for the binding tag TablelistBody. #------------------------------------------------------------------------------ proc tablelist::defineTablelistBody {} { variable priv array set priv { x "" y "" afterId "" prevRow "" prevCol "" selection {} clicked 0 } bind TablelistBody { if {[winfo exists %W]} { foreach {tablelist::W tablelist::x tablelist::y} \ [tablelist::convEventFields %W %x %y] {} set tablelist::priv(x) $tablelist::x set tablelist::priv(y) $tablelist::y set tablelist::priv(row) [$tablelist::W nearest $tablelist::y] set tablelist::priv(col) [$tablelist::W nearestcolumn $tablelist::x] set tablelist::priv(clicked) 1 set tablelist::priv(clickTime) %t set tablelist::priv(clickedInEditWin) 0 if {[$tablelist::W cget -setfocus]} { focus [$tablelist::W bodypath] } tablelist::condEditContainingCell $tablelist::W \ $tablelist::x $tablelist::y tablelist::condBeginMove $tablelist::W $tablelist::priv(row) tablelist::beginSelect $tablelist::W \ $tablelist::priv(row) $tablelist::priv(col) } } bind TablelistBody { # Empty script } bind TablelistBody { if {$tablelist::priv(clicked) && %t - $tablelist::priv(clickTime) < 300} { continue } foreach {tablelist::W tablelist::x tablelist::y} \ [tablelist::convEventFields %W %x %y] {} if {[string compare $tablelist::priv(x) ""] == 0 || [string compare $tablelist::priv(y) ""] == 0} { set tablelist::priv(x) $tablelist::x set tablelist::priv(y) $tablelist::y } set tablelist::priv(prevX) $tablelist::priv(x) set tablelist::priv(prevY) $tablelist::priv(y) set tablelist::priv(x) $tablelist::x set tablelist::priv(y) $tablelist::y tablelist::condAutoScan $tablelist::W tablelist::motion $tablelist::W \ [$tablelist::W nearest $tablelist::y] \ [$tablelist::W nearestcolumn $tablelist::x] tablelist::condShowTarget $tablelist::W $tablelist::y } bind TablelistBody { foreach {tablelist::W tablelist::x tablelist::y} \ [tablelist::convEventFields %W %x %y] {} set tablelist::priv(x) "" set tablelist::priv(y) "" after cancel $tablelist::priv(afterId) set tablelist::priv(afterId) "" set tablelist::priv(releasedInEditWin) 0 if {$tablelist::priv(clicked) && %t - $tablelist::priv(clickTime) < 300} { tablelist::moveOrActivate $tablelist::W \ $tablelist::priv(row) $tablelist::priv(col) } else { tablelist::moveOrActivate $tablelist::W \ [$tablelist::W nearest $tablelist::y] \ [$tablelist::W nearestcolumn $tablelist::x] } set tablelist::priv(clicked) 0 tablelist::condEvalInvokeCmd $tablelist::W } bind TablelistBody { foreach {tablelist::W tablelist::x tablelist::y} \ [tablelist::convEventFields %W %x %y] {} tablelist::beginExtend $tablelist::W \ [$tablelist::W nearest $tablelist::y] \ [$tablelist::W nearestcolumn $tablelist::x] } bind TablelistBody { foreach {tablelist::W tablelist::x tablelist::y} \ [tablelist::convEventFields %W %x %y] {} tablelist::beginToggle $tablelist::W \ [$tablelist::W nearest $tablelist::y] \ [$tablelist::W nearestcolumn $tablelist::x] } bind TablelistBody { tablelist::condEditActiveCell [tablelist::getTablelistPath %W] } bind TablelistBody { tablelist::condEditActiveCell [tablelist::getTablelistPath %W] } bind TablelistBody { tablelist::nextPrevCell [tablelist::getTablelistPath %W] 1 } bind TablelistBody { tablelist::nextPrevCell [tablelist::getTablelistPath %W] -1 } bind TablelistBody <> { tablelist::nextPrevCell [tablelist::getTablelistPath %W] -1 } bind TablelistBody { tablelist::upDown [tablelist::getTablelistPath %W] -1 } bind TablelistBody { tablelist::upDown [tablelist::getTablelistPath %W] 1 } bind TablelistBody { tablelist::leftRight [tablelist::getTablelistPath %W] -1 } bind TablelistBody { tablelist::leftRight [tablelist::getTablelistPath %W] 1 } bind TablelistBody { tablelist::priorNext [tablelist::getTablelistPath %W] -1 } bind TablelistBody { tablelist::priorNext [tablelist::getTablelistPath %W] 1 } bind TablelistBody { tablelist::homeEnd [tablelist::getTablelistPath %W] Home } bind TablelistBody { tablelist::homeEnd [tablelist::getTablelistPath %W] End } bind TablelistBody { tablelist::firstLast [tablelist::getTablelistPath %W] first } bind TablelistBody { tablelist::firstLast [tablelist::getTablelistPath %W] last } bind TablelistBody { tablelist::extendUpDown [tablelist::getTablelistPath %W] -1 } bind TablelistBody { tablelist::extendUpDown [tablelist::getTablelistPath %W] 1 } bind TablelistBody { tablelist::extendLeftRight [tablelist::getTablelistPath %W] -1 } bind TablelistBody { tablelist::extendLeftRight [tablelist::getTablelistPath %W] 1 } bind TablelistBody { tablelist::extendToHomeEnd [tablelist::getTablelistPath %W] Home } bind TablelistBody { tablelist::extendToHomeEnd [tablelist::getTablelistPath %W] End } bind TablelistBody { tablelist::extendToFirstLast [tablelist::getTablelistPath %W] first } bind TablelistBody { tablelist::extendToFirstLast [tablelist::getTablelistPath %W] last } bind TablelistBody { set tablelist::W [tablelist::getTablelistPath %W] tablelist::beginSelect $tablelist::W \ [$tablelist::W index active] [$tablelist::W columnindex active] } bind TablelistBody