Changeset 1923 for branches/blt4/gui/scripts/combobox.tcl
- Timestamp:
- Oct 18, 2010, 11:59:55 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/blt4/gui/scripts/combobox.tcl
r1897 r1923 50 50 51 51 blt::bitmap define ComboboxArrow { 52 53 54 55 52 #define arrow_width 8 53 #define arrow_height 4 54 static unsigned char arrow_bits[] = { 55 0xfe, 0x7c, 0x38, 0x10}; 56 56 } 57 57 private variable _value2label 58 58 private variable _label2value 59 59 } 60 60 61 61 itk::usual Combobox { 62 62 keep -cursor -font … … 73 73 74 74 itk_component add button { 75 76 75 button $itk_interior.btn -bitmap ComboboxArrow -padx 0 \ 76 -borderwidth 1 -relief raised -highlightthickness 0 77 77 } { 78 79 80 78 usual 79 ignore -highlightthickness -highlightbackground -highlightcolor 80 ignore -borderwidth -relief 81 81 } 82 82 pack $itk_component(button) -side right -fill y 83 83 84 84 itk_component add entry { 85 85 entry $itk_interior.entry -borderwidth 0 -relief flat 86 86 } { 87 88 89 90 91 92 93 94 87 usual 88 keep -width 89 rename -highlightbackground -textbackground textBackground Background 90 rename -background -textbackground textBackground Background 91 rename -foreground -textforeground textForeground Foreground 92 rename -disabledbackground -textbackground textBackground Background 93 rename -disabledforeground -textforeground textForeground Foreground 94 ignore -borderwidth -relief 95 95 } 96 96 pack $itk_component(entry) -side left -expand yes -fill both 97 97 98 98 bind $itk_component(entry) <KeyPress-Return> \ 99 99 [itcl::code $this _entry apply] 100 100 bind $itk_component(entry) <ButtonPress> \ 101 101 [itcl::code $this _entry click] 102 102 103 103 itk_component add ddlist { 104 105 106 104 Rappture::Dropdownlist $itk_component(button).ddlist \ 105 -postcommand [itcl::code $this _dropdown post] \ 106 -unpostcommand [itcl::code $this _dropdown unpost] \ 107 107 } 108 108 109 109 bind $itk_component(ddlist) <<DropdownlistSelect>> \ 110 110 [itcl::code $this _dropdown select] 111 111 112 112 $itk_component(button) configure -command \ 113 113 [list $itk_component(ddlist) post $itk_component(hull) left] 114 114 115 115 eval itk_initialize $args … … 126 126 itcl::body Rappture::Combobox::value {args} { 127 127 if {[llength $args] == 1} { 128 129 130 131 132 133 134 135 136 137 128 set newval [lindex $args 0] 129 130 $itk_component(entry) configure -state normal 131 $itk_component(entry) delete 0 end 132 $itk_component(entry) insert 0 $newval 133 if {!$itk_option(-editable)} { 134 $itk_component(entry) configure -state disabled 135 } 136 137 after 10 [list catch [list event generate $itk_component(hull) <<Value>>]] 138 138 } elseif {[llength $args] != 0} { 139 139 error "wrong # args: should be \"value ?newval?\"" 140 140 } 141 141 return [$itk_component(entry) get] … … 152 152 itcl::body Rappture::Combobox::translate {value {defValue ""}} { 153 153 foreach {val label} [choices get -both] { 154 155 156 154 if {$label == $value} { 155 return $val 156 } 157 157 } 158 158 return $defValue … … 166 166 itcl::body Rappture::Combobox::label { myValue } { 167 167 foreach {val label} [choices get -both] { 168 169 170 168 if {$myValue == $val} { 169 return $label 170 } 171 171 } 172 172 return "" … … 182 182 set value [translate $raw "badValue"] 183 183 if { $value != "badValue" } { 184 184 return $value 185 185 } 186 186 return $raw … … 215 215 itcl::body Rappture::Combobox::_entry {option} { 216 216 switch -- $option { 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 217 apply { 218 if {$itk_option(-editable) && $itk_option(-state) == "normal"} { 219 event generate $itk_component(hull) <<Value>> 220 } 221 } 222 click { 223 if {!$itk_option(-editable) && $itk_option(-state) == "normal"} { 224 $itk_component(button) configure -relief sunken 225 update idletasks; after 100 226 $itk_component(button) configure -relief raised 227 228 $itk_component(ddlist) post $itk_component(hull) left 229 } 230 } 231 default { 232 error "bad option \"$option\": should be apply, click" 233 } 234 234 } 235 235 } … … 248 248 itcl::body Rappture::Combobox::_dropdown {option} { 249 249 switch -- $option { 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 250 post { 251 set value [$itk_component(entry) get] 252 set i [$itk_component(ddlist) index -label $value] 253 if {$i >= 0} { 254 $itk_component(ddlist) select clear 0 end 255 $itk_component(ddlist) select set $i 256 } 257 } 258 unpost { 259 if {$itk_option(-editable)} { 260 focus $itk_component(entry) 261 } 262 } 263 select { 264 set val [$itk_component(ddlist) current -label] 265 if {"" != $val} { 266 value $val 267 } 268 } 269 default { 270 error "bad option \"$option\": should be post, unpost, select" 271 } 272 272 } 273 273 } … … 281 281 itcl::body Rappture::Combobox::_fixState {} { 282 282 if {$itk_option(-state) == "normal"} { 283 284 285 286 287 288 283 $itk_component(button) configure -state normal 284 $itk_component(entry) configure \ 285 -background $itk_option(-textbackground) \ 286 -foreground $itk_option(-textforeground) \ 287 -disabledbackground $itk_option(-textbackground) \ 288 -disabledforeground $itk_option(-textforeground) 289 289 } else { 290 291 292 293 294 295 290 $itk_component(button) configure -state disabled 291 $itk_component(entry) configure \ 292 -background $itk_option(-disabledbackground) \ 293 -foreground $itk_option(-disabledforeground) \ 294 -disabledbackground $itk_option(-disabledbackground) \ 295 -disabledforeground $itk_option(-disabledforeground) 296 296 } 297 297 298 298 if {$itk_option(-editable)} { 299 300 301 302 303 299 if {$itk_option(-state) == "normal"} { 300 $itk_component(entry) configure -state normal 301 } else { 302 $itk_component(entry) configure -state disabled 303 } 304 304 } else { 305 305 $itk_component(entry) configure -state disabled 306 306 } 307 307 308 308 if {!$itk_option(-editable) || $itk_option(-state) != "normal"} { 309 310 311 312 309 # can't keep focus here -- move it along to the next widget 310 if {[focus] == $itk_component(entry)} { 311 focus [tk_focusNext [focus]] 312 } 313 313 } 314 314 } … … 319 319 itcl::configbody Rappture::Combobox::editable { 320 320 if {![string is boolean -strict $itk_option(-editable)]} { 321 321 error "bad value \"$itk_option(-editable)\": should be boolean" 322 322 } 323 323 _fixState … … 330 330 set valid {normal disabled} 331 331 if {[lsearch -exact $valid $itk_option(-state)] < 0} { 332 332 error "bad value \"$itk_option(-state)\": should be [join $valid {, }]" 333 333 } 334 334 _fixState
Note: See TracChangeset
for help on using the changeset viewer.