1 # vim: foldmarker=<<<,>>>
4 # onchange(id,text) - Fired when the data is changed
6 option add *Lookup.buttonBorderwidth 1 widgetDefault
7 option add *Lookup.buttonPadX 2 widgetDefault
8 option add *Lookup.buttonPadY 0 widgetDefault
11 inherit tlc::Mywidget tlc::Handlers tlc::Textvariable tlc::Signalsource
17 variable button_label "..."
18 variable lookup_command {}
19 variable state "normal"
21 method set_data {id text}
24 method selected_ref {}
33 method textvariable_changed {newvalue}
38 configbody tlc::Lookup::lookup_command { #<<<1
39 $signals(lookup_set) set_state [expr {$lookup_command != {}}]
40 log debug "$w lookup_command: ([$signals(lookup_set) state]) ($lookup_command)"
44 configbody tlc::Lookup::state { #<<<1
45 $signals(enabled) set_state [expr {$state == "normal"}]
46 log debug "$w state: ([$signals(enabled) state]) ($state)"
50 configbody tlc::Lookup::button_label { #<<<1
52 switch -- [string index $button_label 0] {
55 -text "" -image [string range $button_label 1 end]
60 -text $button_label -image ""
66 body tlc::Lookup::constructor {args} { #<<<1
67 tlc::Signal #auto signals(lookup_set) -name "$w lookup_set"
68 tlc::Signal #auto signals(enabled) -name "$w enabled"
69 tlc::Signal #auto signals(item_selected) -name "$w item_selected"
71 $signals(enabled) set_state [expr {$state == "normal"}]
73 itk_component add entry {
74 entry $w.entry -state disabled -background $tlc::config(textbackground) \
75 -textvariable [scope text]
78 ignore -background -state -textvariable
80 switch -- $::tcl_version {
88 ignore -disabledbackground
89 # keep -disabledbackground
94 bind $w.entry <Button-1> [code $this fire_lookup]
96 itk_component add button {
97 button $w.button -command [code $this fire_lookup]
101 rename -borderwidth -buttonborderwidth buttonBorderwidth ButtonBorderwidth
102 rename -padx -buttonpadx buttonPadX ButtonPadX
103 rename -pady -buttonpady buttonPadY ButtonPadY
106 switch -- $::tcl_version {
111 tlc::StateToggle #auto toggles(entry) $w.entry \
112 -background [list $tlc::config(disabledbackground) $tlc::config(textbackground)]
116 tlc::StateToggle #auto toggles(entry) $w.entry \
117 -background [list $tlc::config(disabledbackground) $tlc::config(textbackground)] \
118 -disabledbackground [list $tlc::config(disabledbackground) $tlc::config(textbackground)]
122 tlc::StateToggle #auto toggles(button) $w.button \
123 -state {disabled normal}
125 $toggles(entry) attach_signal $signals(enabled)
126 $toggles(button) attach_signal $signals(enabled)
127 $toggles(button) attach_signal $signals(lookup_set)
130 $w.entry 1,1 -fill x \
131 $w.button 1,2 -fill y
132 table configure $w c2 -resize none
134 eval itk_initialize $args
138 body tlc::Lookup::destructor {} { #<<<1
144 body tlc::Lookup::fire_lookup {} { #<<<1
145 if {![$signals(enabled) state]} return
146 if {![$signals(lookup_set) state]} return
147 set res [uplevel #0 $lookup_command [list $id $text]]
148 set status [lindex $res 0]
150 set_data [lindex $res 1] [lindex $res 2]
155 body tlc::Lookup::set_data {id newtext} { #<<<1
161 $signals(item_selected) set_state [expr {$id != ""}]
163 invoke_handlers onchange $id $text
167 body tlc::Lookup::get_id {} { #<<<1
172 body tlc::Lookup::get_text {} { #<<<1
177 body tlc::Lookup::selected_ref {} { #<<<1
178 log warning "selected_ref is deprecated. use signal_ref item_selected\n[tlc::stackdump]"
179 return $signals(item_selected)
183 body tlc::Lookup::textvariable_changed {newvalue} { #<<<1
186 if {$newvalue == ""} {