Changeset 1929 for trunk/gui/scripts/dropdownlist.tcl
- Timestamp:
- Oct 22, 2010, 4:06:10 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/dropdownlist.tcl
r1342 r1929 50 50 itcl::body Rappture::Dropdownlist::constructor {args} { 51 51 itk_component add scroller { 52 53 52 Rappture::Scroller $itk_interior.sc \ 53 -xscrollmode off -yscrollmode auto 54 54 } 55 55 pack $itk_component(scroller) -expand yes -fill both 56 56 57 57 itk_component add list { 58 59 60 58 listbox $itk_component(scroller).list \ 59 -selectmode single -exportselection no \ 60 -highlightthickness 0 61 61 } { 62 63 64 65 66 62 usual 63 rename -background -textbackground textBackground Background 64 rename -foreground -textforeground textForeground Foreground 65 ignore -highlightthickness -highlightbackground -highlightcolor 66 keep -relief 67 67 } 68 68 $itk_component(scroller) contents $itk_component(list) … … 77 77 set i [lsearch $btags [winfo class $itk_component(list)]] 78 78 if {$i < 0} { 79 79 set i end 80 80 } 81 81 set btags [linsert $btags [expr {$i+1}] RapptureDropdownlist-$this] … … 95 95 itcl::body Rappture::Dropdownlist::insert {pos args} { 96 96 if {"end" == $pos} { 97 97 set pos [llength $_values] 98 98 } elseif {![string is integer -strict $pos]} { 99 99 error "bad index \"$pos\": should be integer or \"end\"" 100 100 } 101 101 102 102 if {[llength $args] == 1} { 103 103 set args [lindex $args 0] 104 104 } 105 105 if {[llength $args] % 2 != 0} { 106 106 error "wrong # args: should be \"insert pos ?value label ...?\"" 107 107 } 108 108 109 109 foreach {val label} $args { 110 111 112 113 114 115 116 110 if {$label == "--"} { 111 set label $val 112 } 113 set _values [linsert $_values $pos $val] 114 set _labels [linsert $_labels $pos $label] 115 $itk_component(list) insert $pos $label 116 incr pos 117 117 } 118 118 } … … 127 127 itcl::body Rappture::Dropdownlist::delete {first {last ""}} { 128 128 if {$last == ""} { 129 129 set last $first 130 130 } 131 131 if {![regexp {^[0-9]+|end$} $first]} { 132 132 error "bad index \"$first\": should be integer or \"end\"" 133 133 } 134 134 if {![regexp {^[0-9]+|end$} $last]} { 135 135 error "bad index \"$last\": should be integer or \"end\"" 136 136 } 137 137 … … 151 151 set first [lindex $args 0] 152 152 if {$first == "-value" || $first == "-label"} { 153 154 153 set format $first 154 set args [lrange $args 1 end] 155 155 } elseif {[llength $args] > 1} { 156 156 error "bad option \"$first\": should be -value or -label" 157 157 } 158 158 if {[llength $args] != 1} { 159 159 error "wrong # args: should be \"index ?-value? ?-label? string\"" 160 160 } 161 161 set value [lindex $args 0] 162 162 163 163 switch -- $format { 164 165 164 -value { return [lsearch -exact $_values $value] } 165 -label { return [lsearch -exact $_labels $value] } 166 166 } 167 167 return -1 … … 180 180 set first [lindex $args 0] 181 181 if {[string index $first 0] == "-"} { 182 183 184 185 186 187 182 set choices {-value -label -both} 183 if {[lsearch $choices $first] < 0} { 184 error "bad option \"$first\": should be [join [lsort $choices] {, }]" 185 } 186 set format $first 187 set args [lrange $args 1 end] 188 188 } 189 189 190 190 # return the whole list or just a single value 191 191 if {[llength $args] > 1} { 192 192 error "wrong # args: should be \"get ?-value|-label|-both? ?index?\"" 193 193 } 194 194 if {[llength $args] == 0} { 195 196 197 195 set vlist $_values 196 set llist $_labels 197 set op lappend 198 198 } else { 199 200 201 202 199 set i [lindex $args 0] 200 set vlist [list [lindex $_values $i]] 201 set llist [list [lindex $_labels $i]] 202 set op set 203 203 } 204 204 … … 206 206 set rlist "" 207 207 foreach v $vlist l $llist { 208 209 210 211 212 208 switch -- $format { 209 -value { $op rlist $v } 210 -label { $op rlist $l } 211 -both { lappend rlist $v $l } 212 } 213 213 } 214 214 return $rlist … … 232 232 itcl::body Rappture::Dropdownlist::select {option args} { 233 233 if {$option == "set"} { 234 234 $itk_component(list) activate [lindex $args 0] 235 235 } 236 236 eval $itk_component(list) selection $option $args … … 246 246 set i [$itk_component(list) curselection] 247 247 if {$i != ""} { 248 249 250 251 252 253 254 255 248 switch -- $what { 249 -value { return [lindex $_values $i] } 250 -label { return [lindex $_labels $i] } 251 -both { return [list [lindex $_values $i] [lindex $_labels $i]] } 252 default { 253 error "bad option \"$what\": should be -value, -label, -both" 254 } 255 } 256 256 } 257 257 return "" … … 271 271 set maxw 0 272 272 foreach str $_labels { 273 274 273 set w [font measure $fnt $str] 274 if {$w > $maxw} { set maxw $w } 275 275 } 276 276 if {$widget != ""} { 277 277 if {$maxw < [winfo width $widget]} { set maxw [winfo width $widget] } 278 278 } 279 279 set avg [font measure $fnt "n"] … … 281 281 282 282 if {$widget != ""} { 283 284 285 286 287 288 289 290 283 set y [expr {[winfo rooty $widget]+[winfo height $widget]}] 284 set h [font metrics $fnt -linespace] 285 set lines [expr {double([winfo screenheight $widget]-$y)/$h}] 286 if {[llength $_labels] < $lines} { 287 $itk_component(list) configure -height [llength $_labels] 288 } else { 289 $itk_component(list) configure -height 10 290 } 291 291 } 292 292
Note: See TracChangeset
for help on using the changeset viewer.