1 package require Iwidgets
3 option add *Dropselect.highlightThickness 1 widgetDefault
4 option add *Dropselect.borderWidth 2 widgetDefault
5 option add *Dropselect.labelPos w widgetDefault
6 option add *Dropselect.labelMargin 2 widgetDefault
7 option add *Dropselect.popupCursor arrow widgetDefault
8 option add *Dropselect.indicatoron 1 widgetDefault
9 option add *Dropselect.menuRelief raised widgetDefault
10 #option add *Dropselect.menuBorderWidth 2 widgetDefault
13 ::itk::usual Dropselect {
14 keep -background -font -cursor
18 class tlc::Dropselect {
19 inherit ::iwidgets::Optionmenu
20 #tlc::Stategate_target
24 itk_option define -postcommand postCommand Command {}
25 itk_option define -menuborderwidth menuBorderWidth BorderWidth 2
26 itk_option define -pady padY PadY 4
32 method selectid {newitem}
33 method get_selected_id {}
46 configbody tlc::Dropselect::postcommand {
47 set m [component popupMenu]
48 $m configure -postcommand $itk_option(-postcommand)
52 configbody tlc::Dropselect::menuborderwidth {
53 $itk_component(menuBtn) configure \
54 -borderwidth $itk_option(-menuborderwidth)
58 configbody tlc::Dropselect::pady {
59 $itk_component(menuBtn) configure \
60 -pady $itk_option(-pady)
64 body tlc::Dropselect::constructor {args} {
65 configure -command [code $this newitem]
67 eval itk_initialize $args
71 configbody tlc::Dropselect::callback {
76 configbody tlc::Dropselect::choices {
83 foreach choice $choices {
84 set id [lindex $choice 0]
85 set text [lindex $choice 1]
94 if {[llength $values] > 0} {
97 if {$selected == ""} {
100 # set selectedindex [lsearch -exact $choices $selected]
101 if {![info exists idmap($selected)]} {
104 set selectedindex $idmap($selected)
106 select $selectedindex
113 proc tlc::dropselect {pathName args} {
114 uplevel tlc::Dropselect $pathName $args
118 body tlc::Dropselect::newitem {} {
120 set selid [get_selected_id]
124 if {$callback != ""} {
125 uplevel #0 $callback [list $selid]
130 body tlc::Dropselect::selectid {newitem} {
131 # set index [lsearch -exact $choices $newitem]
132 if {![info exists idmap($newitem)]} {
135 set index $idmap($newitem)
136 if {$index == -1} {return $index}
144 body tlc::Dropselect::get_selected_id {} {
145 return [lindex [lindex $choices [index select]] 0]