# # A mocked-up example showing simple listbox-like behavior in a text # widget. Not terribly intelligent in this implementation. (only the # single mouse click button is defined to select the whole row. The # rest of the behavior is still a text widget. # # One big limitation, you can't bind to the name you gave the widget, # so if you want to, you must bind to the name with a '_tlb' appended. # # You must also pack with the '_tlb' appended like this: # textlb .a # pack .a_tlb # from here on out you can refer to this as '.a' like this: # .a insert 0 "Foo" image1 # # The big addition, the insert command can be used with the syntax: # .t insert {idx|end} text ?image? proc textlb { w } { regsub -all {\.} $w "_" wname uplevel #0 "set textlb_${wname}(length) 0" proc $w {args} " ${w}_real $w $wname \$args " proc ${w}_real {w wname args} { global textlb_${wname} set length [subst $[subst textlb_${wname}(length)]] set arglist [lindex $args 0] set arg [lindex $arglist 0] if {$arg == "insert"} { incr textlb_${wname}(length) if {[llength $arglist] > 3} { button ${w}_tlb_$length -image [lindex $arglist 3] -bd 0 bindtags ${w}_tlb_$length {${w}_tlb_$length . all} if {[lindex $arglist 1] != "end"} { ${w}_tlb insert [lindex $arglist 1].0 \ "[lindex $arglist 2]\n" ${w}_tlb window create [lindex $arglist 1].0 \ -window ${w}_tlb_${length} } else { ${w}_tlb window create end -window ${w}_tlb_${length} ${w}_tlb insert end "[lindex $arglist 2]\n" } } else { ${w}_tlb insert [lindex $arglist 1].0 "[lindex $arglist 2]\n" } } else { eval "${w}_tlb $arglist" } } text ${w}_tlb bind ${w}_tlb <1> { set textcur "[%W index @%x,%y]" %W tag remove sel 0.0 $textcur %W tag add sel [%W index "$textcur linestart"] \ [%W index "$textcur lineend"] %W tag remove sel [%W index "$textcur lineend"] end break; } return ${w}_tlb }