Ignore:
Timestamp:
Oct 18, 2010, 11:59:55 AM (14 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/blt4/gui/scripts/combobox.tcl

    r1897 r1923  
    5050
    5151    blt::bitmap define ComboboxArrow {
    52         #define arrow_width 8
    53         #define arrow_height 4
    54         static unsigned char arrow_bits[] = {
    55            0xfe, 0x7c, 0x38, 0x10};
     52        #define arrow_width 8
     53        #define arrow_height 4
     54        static unsigned char arrow_bits[] = {
     55           0xfe, 0x7c, 0x38, 0x10};
    5656    }
    5757    private variable _value2label
    5858    private variable _label2value
    5959}
    60                                                                                
     60                                                                               
    6161itk::usual Combobox {
    6262    keep -cursor -font
     
    7373
    7474    itk_component add button {
    75         button $itk_interior.btn -bitmap ComboboxArrow -padx 0 \
    76             -borderwidth 1 -relief raised -highlightthickness 0
     75        button $itk_interior.btn -bitmap ComboboxArrow -padx 0 \
     76            -borderwidth 1 -relief raised -highlightthickness 0
    7777    } {
    78         usual
    79         ignore -highlightthickness -highlightbackground -highlightcolor
    80         ignore -borderwidth -relief
     78        usual
     79        ignore -highlightthickness -highlightbackground -highlightcolor
     80        ignore -borderwidth -relief
    8181    }
    8282    pack $itk_component(button) -side right -fill y
    8383
    8484    itk_component add entry {
    85         entry $itk_interior.entry -borderwidth 0 -relief flat
     85        entry $itk_interior.entry -borderwidth 0 -relief flat
    8686    } {
    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
     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
    9595    }
    9696    pack $itk_component(entry) -side left -expand yes -fill both
    9797
    9898    bind $itk_component(entry) <KeyPress-Return> \
    99         [itcl::code $this _entry apply]
     99        [itcl::code $this _entry apply]
    100100    bind $itk_component(entry) <ButtonPress> \
    101         [itcl::code $this _entry click]
     101        [itcl::code $this _entry click]
    102102
    103103    itk_component add ddlist {
    104         Rappture::Dropdownlist $itk_component(button).ddlist \
    105             -postcommand [itcl::code $this _dropdown post] \
    106             -unpostcommand [itcl::code $this _dropdown unpost] \
     104        Rappture::Dropdownlist $itk_component(button).ddlist \
     105            -postcommand [itcl::code $this _dropdown post] \
     106            -unpostcommand [itcl::code $this _dropdown unpost] \
    107107    }
    108108
    109109    bind $itk_component(ddlist) <<DropdownlistSelect>> \
    110         [itcl::code $this _dropdown select]
     110        [itcl::code $this _dropdown select]
    111111
    112112    $itk_component(button) configure -command \
    113         [list $itk_component(ddlist) post $itk_component(hull) left]
     113        [list $itk_component(ddlist) post $itk_component(hull) left]
    114114
    115115    eval itk_initialize $args
     
    126126itcl::body Rappture::Combobox::value {args} {
    127127    if {[llength $args] == 1} {
    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>>]]
     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>>]]
    138138    } elseif {[llength $args] != 0} {
    139         error "wrong # args: should be \"value ?newval?\""
     139        error "wrong # args: should be \"value ?newval?\""
    140140    }
    141141    return [$itk_component(entry) get]
     
    152152itcl::body Rappture::Combobox::translate {value {defValue ""}} {
    153153    foreach {val label} [choices get -both] {
    154         if {$label == $value} {
    155             return $val
    156         }
     154        if {$label == $value} {
     155            return $val
     156        }
    157157    }
    158158    return $defValue
     
    166166itcl::body Rappture::Combobox::label { myValue } {
    167167    foreach {val label} [choices get -both] {
    168         if {$myValue == $val} {
    169             return $label
    170         }
     168        if {$myValue == $val} {
     169            return $label
     170        }
    171171    }
    172172    return ""
     
    182182    set value [translate $raw "badValue"]
    183183    if { $value != "badValue" } {
    184         return $value
     184        return $value
    185185    }
    186186    return $raw
     
    215215itcl::body Rappture::Combobox::_entry {option} {
    216216    switch -- $option {
    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         }
     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        }
    234234    }
    235235}
     
    248248itcl::body Rappture::Combobox::_dropdown {option} {
    249249    switch -- $option {
    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         }
     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        }
    272272    }
    273273}
     
    281281itcl::body Rappture::Combobox::_fixState {} {
    282282    if {$itk_option(-state) == "normal"} {
    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)
     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)
    289289    } else {
    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)
     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)
    296296    }
    297297
    298298    if {$itk_option(-editable)} {
    299         if {$itk_option(-state) == "normal"} {
    300             $itk_component(entry) configure -state normal
    301         } else {
    302             $itk_component(entry) configure -state disabled
    303         }
     299        if {$itk_option(-state) == "normal"} {
     300            $itk_component(entry) configure -state normal
     301        } else {
     302            $itk_component(entry) configure -state disabled
     303        }
    304304    } else {
    305         $itk_component(entry) configure -state disabled
     305        $itk_component(entry) configure -state disabled
    306306    }
    307307
    308308    if {!$itk_option(-editable) || $itk_option(-state) != "normal"} {
    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         }
     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        }
    313313    }
    314314}
     
    319319itcl::configbody Rappture::Combobox::editable {
    320320    if {![string is boolean -strict $itk_option(-editable)]} {
    321         error "bad value \"$itk_option(-editable)\": should be boolean"
     321        error "bad value \"$itk_option(-editable)\": should be boolean"
    322322    }
    323323    _fixState
     
    330330    set valid {normal disabled}
    331331    if {[lsearch -exact $valid $itk_option(-state)] < 0} {
    332         error "bad value \"$itk_option(-state)\": should be [join $valid {, }]"
     332        error "bad value \"$itk_option(-state)\": should be [join $valid {, }]"
    333333    }
    334334    _fixState
Note: See TracChangeset for help on using the changeset viewer.