Changeset 1342 for trunk/gui/scripts/combobox.tcl
- Timestamp:
- Mar 18, 2009 2:59:21 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/combobox.tcl
r1277 r1342 48 48 49 49 blt::bitmap define ComboboxArrow { 50 51 52 53 54 } 55 } 56 50 #define arrow_width 8 51 #define arrow_height 4 52 static unsigned char arrow_bits[] = { 53 0xfe, 0x7c, 0x38, 0x10}; 54 } 55 } 56 57 57 itk::usual Combobox { 58 58 keep -cursor -font … … 69 69 70 70 itk_component add button { 71 72 71 button $itk_interior.btn -bitmap ComboboxArrow -padx 0 \ 72 -borderwidth 1 -relief raised -highlightthickness 0 73 73 } { 74 75 76 74 usual 75 ignore -highlightthickness -highlightbackground -highlightcolor 76 ignore -borderwidth -relief 77 77 } 78 78 pack $itk_component(button) -side right -fill y 79 79 80 80 itk_component add entry { 81 81 entry $itk_interior.entry -borderwidth 0 -relief flat 82 82 } { 83 84 85 86 87 88 89 90 83 usual 84 keep -width 85 rename -highlightbackground -textbackground textBackground Background 86 rename -background -textbackground textBackground Background 87 rename -foreground -textforeground textForeground Foreground 88 rename -disabledbackground -textbackground textBackground Background 89 rename -disabledforeground -textforeground textForeground Foreground 90 ignore -borderwidth -relief 91 91 } 92 92 pack $itk_component(entry) -side left -expand yes -fill both 93 93 94 94 bind $itk_component(entry) <KeyPress-Return> \ 95 95 [itcl::code $this _entry apply] 96 96 bind $itk_component(entry) <ButtonPress> \ 97 97 [itcl::code $this _entry click] 98 98 99 99 itk_component add ddlist { 100 101 102 100 Rappture::Dropdownlist $itk_component(button).ddlist \ 101 -postcommand [itcl::code $this _dropdown post] \ 102 -unpostcommand [itcl::code $this _dropdown unpost] \ 103 103 } 104 104 105 105 bind $itk_component(ddlist) <<DropdownlistSelect>> \ 106 106 [itcl::code $this _dropdown select] 107 107 108 108 $itk_component(button) configure -command \ 109 109 [list $itk_component(ddlist) post $itk_component(hull) left] 110 110 111 111 eval itk_initialize $args … … 122 122 itcl::body Rappture::Combobox::value {args} { 123 123 if {[llength $args] == 1} { 124 125 126 127 128 129 130 131 132 133 124 set newval [lindex $args 0] 125 126 $itk_component(entry) configure -state normal 127 $itk_component(entry) delete 0 end 128 $itk_component(entry) insert 0 $newval 129 if {!$itk_option(-editable)} { 130 $itk_component(entry) configure -state disabled 131 } 132 133 after 10 [list catch [list event generate $itk_component(hull) <<Value>>]] 134 134 } elseif {[llength $args] != 0} { 135 135 error "wrong # args: should be \"value ?newval?\"" 136 136 } 137 137 return [$itk_component(entry) get] … … 148 148 itcl::body Rappture::Combobox::translate {value} { 149 149 foreach {val label} [choices get -both] { 150 151 152 150 if {$label == $value} { 151 return $val 152 } 153 153 } 154 154 return "" … … 183 183 itcl::body Rappture::Combobox::_entry {option} { 184 184 switch -- $option { 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 185 apply { 186 if {$itk_option(-editable) && $itk_option(-state) == "normal"} { 187 event generate $itk_component(hull) <<Value>> 188 } 189 } 190 click { 191 if {!$itk_option(-editable) && $itk_option(-state) == "normal"} { 192 $itk_component(button) configure -relief sunken 193 update idletasks; after 100 194 $itk_component(button) configure -relief raised 195 196 $itk_component(ddlist) post $itk_component(hull) left 197 } 198 } 199 default { 200 error "bad option \"$option\": should be apply, click" 201 } 202 202 } 203 203 } … … 216 216 itcl::body Rappture::Combobox::_dropdown {option} { 217 217 switch -- $option { 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 218 post { 219 set value [$itk_component(entry) get] 220 set i [$itk_component(ddlist) index -label $value] 221 if {$i >= 0} { 222 $itk_component(ddlist) select clear 0 end 223 $itk_component(ddlist) select set $i 224 } 225 } 226 unpost { 227 if {$itk_option(-editable)} { 228 focus $itk_component(entry) 229 } 230 } 231 select { 232 set val [$itk_component(ddlist) current -label] 233 if {"" != $val} { 234 value $val 235 } 236 } 237 default { 238 error "bad option \"$option\": should be post, unpost, select" 239 } 240 240 } 241 241 } … … 249 249 itcl::body Rappture::Combobox::_fixState {} { 250 250 if {$itk_option(-state) == "normal"} { 251 252 253 254 255 256 251 $itk_component(button) configure -state normal 252 $itk_component(entry) configure \ 253 -background $itk_option(-textbackground) \ 254 -foreground $itk_option(-textforeground) \ 255 -disabledbackground $itk_option(-textbackground) \ 256 -disabledforeground $itk_option(-textforeground) 257 257 } else { 258 259 260 261 262 263 258 $itk_component(button) configure -state disabled 259 $itk_component(entry) configure \ 260 -background $itk_option(-disabledbackground) \ 261 -foreground $itk_option(-disabledforeground) \ 262 -disabledbackground $itk_option(-disabledbackground) \ 263 -disabledforeground $itk_option(-disabledforeground) 264 264 } 265 265 266 266 if {$itk_option(-editable)} { 267 268 269 270 271 267 if {$itk_option(-state) == "normal"} { 268 $itk_component(entry) configure -state normal 269 } else { 270 $itk_component(entry) configure -state disabled 271 } 272 272 } else { 273 273 $itk_component(entry) configure -state disabled 274 274 } 275 275 276 276 if {!$itk_option(-editable) || $itk_option(-state) != "normal"} { 277 278 279 280 277 # can't keep focus here -- move it along to the next widget 278 if {[focus] == $itk_component(entry)} { 279 focus [tk_focusNext [focus]] 280 } 281 281 } 282 282 } … … 287 287 itcl::configbody Rappture::Combobox::editable { 288 288 if {![string is boolean -strict $itk_option(-editable)]} { 289 289 error "bad value \"$itk_option(-editable)\": should be boolean" 290 290 } 291 291 _fixState … … 298 298 set valid {normal disabled} 299 299 if {[lsearch -exact $valid $itk_option(-state)] < 0} { 300 300 error "bad value \"$itk_option(-state)\": should be [join $valid {, }]" 301 301 } 302 302 _fixState
Note: See TracChangeset
for help on using the changeset viewer.