3 # A combobox widget is basically a listbox widget with an entry
7 # Copyright (c) 1996, Expert Interface Technologies
9 # See the file "license.terms" for information on usage and redistribution
10 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 tixWidgetClass tixComboBox {
13 -classname TixComboBox
14 -superclass tixLabelWidget
16 addhistory align appendhistory flash invoke insert pick popdown
19 -anchor -arrowbitmap -browsecmd -command -crossbitmap
20 -disablecallback -disabledforeground -dropdown -editable
21 -fancy -grab -histlimit -historylimit -history -listcmd
22 -listwidth -prunehistory -selection -selectmode -state
23 -tickbitmap -validatecmd -value -variable
29 -variable -selectmode -state
32 {-arrowbitmap arrowBitmap ArrowBitmap ""}
33 {-anchor anchor Anchor w}
34 {-browsecmd browseCmd BrowseCmd ""}
35 {-command command Command ""}
36 {-crossbitmap crossBitmap CrossBitmap ""}
37 {-disablecallback disableCallback DisableCallback 0 tixVerifyBoolean}
38 {-disabledforeground disabledForeground DisabledForeground #606060}
39 {-dropdown dropDown DropDown true tixVerifyBoolean}
40 {-editable editable Editable false tixVerifyBoolean}
41 {-fancy fancy Fancy false tixVerifyBoolean}
42 {-grab grab Grab global}
43 {-listcmd listCmd ListCmd ""}
44 {-listwidth listWidth ListWidth ""}
45 {-historylimit historyLimit HistoryLimit ""}
46 {-history history History false tixVerifyBoolean}
47 {-prunehistory pruneHistory PruneHistory true tixVerifyBoolean}
48 {-selectmode selectMode SelectMode browse}
49 {-selection selection Selection ""}
50 {-state state State normal}
51 {-validatecmd validateCmd ValidateCmd ""}
52 {-value value Value ""}
53 {-variable variable Variable ""}
54 {-tickbitmap tickBitmap TickBitmap ""}
57 {-histlimit -historylimit}
60 {*Entry.relief sunken}
61 {*TixScrolledListBox.scrollbar auto}
62 {*Listbox.exportSelection false}
63 {*Listbox.takeFocus false}
64 {*shell.borderWidth 2}
65 {*shell.relief raised}
68 {*Button.borderWidth 1}
69 {*Button.highlightThickness 0}
79 {*Entry.background #c3c3c3}
80 {*Label.font -Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-*}
84 # States: normal numbers: for dropdown style
85 # d+digit(s) : for non-dropdown style
87 proc tixComboBox:InitWidgetRec {w} {
90 tixChainMethod $w InitWidgetRec
97 if {$data(-history)} {
101 if ![string compare $data(-arrowbitmap) ""] {
102 set data(-arrowbitmap) [tix getbitmap cbxarrow]
104 if ![string compare $data(-crossbitmap) ""] {
105 set data(-crossbitmap) [tix getbitmap cross]
107 if ![string compare $data(-tickbitmap) ""] {
108 set data(-tickbitmap) [tix getbitmap tick]
112 proc tixComboBox:ConstructFramedWidget {w frame} {
115 tixChainMethod $w ConstructFramedWidget $frame
117 if {$data(-dropdown)} {
118 tixComboBox:ConstructEntryFrame $w $frame
119 tixComboBox:ConstructListShell $w
121 set f1 [frame $frame.f1]
122 set f2 [frame $frame.f2]
124 tixComboBox:ConstructEntryFrame $w $f1
125 tixComboBox:ConstructListFrame $w $f2
126 pack $f1 -side top -pady 2 -fill x
127 pack $f2 -side top -pady 2 -fill both -expand yes
131 proc tixComboBox:ConstructEntryFrame {w frame} {
136 set data(w:entry) [entry $frame.entry]
138 if {!$data(-editable)} {
140 $data(w:entry) config -bg $bg -state disabled -takefocus 1
143 # This is used during "config-state"
145 set data(entryfg) [$data(w:entry) cget -fg]
147 # (2) The dropdown button, not necessary when not in dropdown mode
149 set data(w:arrow) [button $frame.arrow -bitmap $data(-arrowbitmap)]
150 if {!$data(-dropdown)} {
151 set xframe [frame $frame.xframe -width 19]
154 # (3) The fancy tick and cross buttons
157 if {$data(-editable)} {
158 set data(w:cross) [button $frame.cross -bitmap $data(-crossbitmap)]
159 set data(w:tick) [button $frame.tick -bitmap $data(-tickbitmap)]
161 pack $frame.cross -side left -padx 1
162 pack $frame.tick -side left -padx 1
164 set data(w:tick) [button $frame.tick -bitmap $data(-tickbitmap)]
165 pack $frame.tick -side left -padx 1
169 if {$data(-dropdown)} {
170 pack $data(w:arrow) -side right -padx 1
171 foreach wid "$data(w:frame) $data(w:label)" {
172 tixAddBindTag $wid TixComboWid
173 tixSetMegaWidget $wid $w TixComboBox
176 pack $xframe -side right -padx 1
178 pack $frame.entry -side right -fill x -expand yes -padx 1
181 proc tixComboBox:ConstructListShell {w} {
184 # Create the shell and the list
185 #------------------------------
186 set data(w:shell) [menu $w.shell -bd 2 -relief raised -tearoff 0]
187 wm overrideredirect $data(w:shell) 1
188 wm withdraw $data(w:shell)
190 set data(w:slistbox) [tixScrolledListBox $data(w:shell).slistbox \
191 -anchor $data(-anchor) -scrollbarspace y \
192 -options {listbox.selectMode "browse"}]
194 set data(w:listbox) [$data(w:slistbox) subwidget listbox]
196 pack $data(w:slistbox) -expand yes -fill both -padx 2 -pady 2
199 proc tixComboBox:ConstructListFrame {w frame} {
202 set data(w:slistbox) [tixScrolledListBox $frame.slistbox \
203 -anchor $data(-anchor)]
205 set data(w:listbox) [$data(w:slistbox) subwidget listbox]
207 pack $data(w:slistbox) -expand yes -fill both
211 proc tixComboBox:SetBindings {w} {
214 tixChainMethod $w SetBindings
216 # (1) Fix the bindings for the combobox
218 bindtags $w "$w TixComboBox [winfo toplevel $w] all"
220 # (2) The entry subwidget
222 tixSetMegaWidget $data(w:entry) $w TixComboBox
224 bindtags $data(w:entry) [list $data(w:entry) Entry TixComboEntry\
225 TixComboWid [winfo toplevel $data(w:entry)] all]
227 # (3) The listbox and slistbox
229 $data(w:slistbox) config -browsecmd \
230 "tixComboBox:LbBrowse $w"
231 $data(w:slistbox) config -command\
232 "tixComboBox:LbCommand $w"
233 $data(w:listbox) config -takefocus 0
235 tixAddBindTag $data(w:listbox) TixComboLb
236 tixAddBindTag $data(w:slistbox) TixComboLb
237 tixSetMegaWidget $data(w:listbox) $w TixComboBox
238 tixSetMegaWidget $data(w:slistbox) $w TixComboBox
242 if {$data(-dropdown)} {
243 $data(w:arrow) config -takefocus 0
244 tixAddBindTag $data(w:arrow) TixComboArrow
245 tixSetMegaWidget $data(w:arrow) $w TixComboBox
247 bind $data(w:root) <1> "tixComboBox:RootDown $w"
248 bind $data(w:root) <ButtonRelease-1> "tixComboBox:RootUp $w"
252 if {$data(-editable)} {
253 $data(w:cross) config -command "tixComboBox:CrossBtn $w" \
256 $data(w:tick) config -command "tixComboBox:Invoke $w" -takefocus 0
259 if {$data(-dropdown)} {
266 proc tixComboBoxBind {} {
267 #----------------------------------------------------------------------
268 # The class bindings for the TixComboBox
270 tixBind TixComboBox <Escape> {
271 if [tixComboBox:EscKey %W] {
275 tixBind TixComboBox <Configure> {
276 tixWidgetDoWhenIdle tixComboBox:align %W
278 # Only the two "linear" detail_fields are for tabbing (moving) among
279 # widgets inside the same toplevel. Other detail_fields are sort
282 tixBind TixComboBox <FocusOut> {
283 if {![string compare %d NotifyNonlinear] ||
284 ![string compare %d NotifyNonlinearVirtual]} {
286 if [info exists %W(cancelTab)] {
289 if [string compare [set %W(-state)] disabled] {
290 if [string compare [set %W(-selection)] [set %W(-value)]] {
291 tixComboBox:Invoke %W
297 tixBind TixComboBox <FocusIn> {
298 if {[tixStrEq %d NotifyNonlinear] ||
299 [tixStrEq %d NotifyNonlinearVirtual]} {
301 focus [%W subwidget entry]
303 # CYGNUS LOCAL: Setting the selection if there is no data
304 # causes backspace to misbehave.
305 if {[[set %W(w:entry)] get] != ""} {
306 [set %W(w:entry)] selection from 0
307 [set %W(w:entry)] selection to end
312 #----------------------------------------------------------------------
313 # The class tixBindings for the arrow button widget inside the TixComboBox
316 tixBind TixComboArrow <1> {
317 tixComboBox:ArrowDown [tixGetMegaWidget %W TixComboBox]
319 tixBind TixComboArrow <ButtonRelease-1> {
320 tixComboBox:ArrowUp [tixGetMegaWidget %W TixComboBox]
322 tixBind TixComboArrow <Escape> {
323 if [tixComboBox:EscKey [tixGetMegaWidget %W TixComboBox]] {
329 #----------------------------------------------------------------------
330 # The class tixBindings for the entry widget inside the TixComboBox
332 tixBind TixComboEntry <Up> {
333 tixComboBox:EntDirKey [tixGetMegaWidget %W TixComboBox] up
335 tixBind TixComboEntry <Down> {
336 tixComboBox:EntDirKey [tixGetMegaWidget %W TixComboBox] down
338 tixBind TixComboEntry <Prior> {
339 tixComboBox:EntDirKey [tixGetMegaWidget %W TixComboBox] pageup
341 tixBind TixComboEntry <Next> {
342 tixComboBox:EntDirKey [tixGetMegaWidget %W TixComboBox] pagedown
344 tixBind TixComboEntry <Return> {
345 tixComboBox:EntReturnKey [tixGetMegaWidget %W TixComboBox]
347 tixBind TixComboEntry <KeyPress> {
348 tixComboBox:EntKeyPress [tixGetMegaWidget %W TixComboBox]
350 tixBind TixComboEntry <Escape> {
351 if [tixComboBox:EscKey [tixGetMegaWidget %W TixComboBox]] {
355 tixBind TixComboEntry <Tab> {
356 if {[set [tixGetMegaWidget %W TixComboBox](-state)] != "disabled"} {
357 if [tixComboBox:EntTab [tixGetMegaWidget %W TixComboBox]] {
362 tixBind TixComboEntry <1> {
363 if {[set [tixGetMegaWidget %W TixComboBox](-state)] != "disabled"} {
367 tixBind TixComboEntry <ButtonRelease-2> {
368 tixComboBox:EntKeyPress [tixGetMegaWidget %W TixComboBox]
371 #----------------------------------------------------------------------
372 # The class bindings for the listbox subwidget
375 tixBind TixComboWid <Escape> {
376 if [tixComboBox:EscKey [tixGetMegaWidget %W TixComboBox]] {
381 #----------------------------------------------------------------------
382 # The class bindings for some widgets inside ComboBox
384 tixBind TixComboWid <ButtonRelease-1> {
385 tixComboBox:WidUp [tixGetMegaWidget %W TixComboBox]
387 tixBind TixComboWid <Escape> {
388 if [tixComboBox:EscKey [tixGetMegaWidget %W TixComboBox]] {
394 #----------------------------------------------------------------------
396 #----------------------------------------------------------------------
397 proc tixComboBox:ArrowDown {w} {
400 if ![string compare $data(-state) disabled] {
406 tixComboBox:GoState 1 $w
409 tixComboBox:GoState 19 $w
412 tixComboBox:StateError $w
417 proc tixComboBox:ArrowUp {w} {
422 tixComboBox:GoState 2 $w
425 # data(ignore) was already set in state 19
426 tixComboBox:GoState 4 $w
429 tixComboBox:GoState 13 $w
432 tixComboBox:StateError $w
437 proc tixComboBox:RootDown {w} {
445 tixComboBox:GoState 3 $w
448 tixComboBox:StateError $w
453 proc tixComboBox:RootUp {w} {
458 tixComboBox:GoState 12 $w
461 # data(ignore) was already set in state 3
462 tixComboBox:GoState 4 $w
465 tixComboBox:GoState 7 $w
468 tixComboBox:StateError $w
473 proc tixComboBox:WidUp {w} {
478 tixComboBox:GoState 12 $w
481 tixComboBox:GoState 13 $w
486 proc tixComboBox:LbBrowse {w args} {
489 set event [tixEvent type]
490 set x [tixEvent flag x]
491 set y [tixEvent flag y]
492 set X [tixEvent flag X]
493 set Y [tixEvent flag Y]
495 if ![string compare $data(-state) disabled] {
503 tixComboBox:GoState 5 $w $x $y $X $Y
506 tixComboBox:GoState 5 $w $x $y $X $Y
509 tixComboBox:GoState n6 $w $x $y $X $Y
512 tixComboBox:StateError $w
519 tixComboBox:GoState 6 $w $x $y $X $Y
522 tixComboBox:GoState n0 $w
525 tixComboBox:StateError $w
530 # Must be a motion event
533 tixComboBox:GoState 9 $w $x $y $X $Y
536 tixComboBox:GoState 5 $w $x $y $X $Y
539 tixComboBox:GoState n6 $w $x $y $X $Y
542 tixComboBox:StateError $w
549 proc tixComboBox:LbCommand {w} {
554 tixComboBox:GoState n1 $w
559 #----------------------------------------------------------------------
560 # General keyboard event
562 # returns 1 if the combobox is in some special state and the Escape key
563 # shouldn't be handled by the toplevel bind tag. As a result, when a combobox
564 # is popped up in a dialog box, Escape will popdown the combo. If the combo
565 # is not popped up, Escape will invoke the toplevel bindtag (which can
566 # pop down the dialog box)
568 proc tixComboBox:EscKey {w} {
571 if ![string compare $data(-state) disabled] {
577 tixComboBox:GoState 17 $w
580 tixComboBox:GoState 16 $w
584 tixComboBox:GoState n4 $w
595 #----------------------------------------
597 #----------------------------------------
598 proc tixComboBox:EntDirKey {w dir} {
601 if ![string compare $data(-state) disabled] {
607 tixComboBox:GoState 10 $w $dir
610 tixComboBox:GoState 11 $w $dir
616 tixComboBox:GoState n3 $w $dir
621 proc tixComboBox:EntReturnKey {w} {
624 if ![string compare $data(-state) disabled] {
630 tixComboBox:GoState 14 $w
633 tixComboBox:GoState 15 $w
639 tixComboBox:GoState n1 $w
644 # Return 1 == break from the binding == no keyboard focus traversal
645 proc tixComboBox:EntTab {w} {
650 tixComboBox:GoState 14 $w
651 set data(cancelTab) ""
655 tixComboBox:GoState 15 $w
656 set data(cancelTab) ""
660 tixComboBox:GoState n1 $w
661 set data(cancelTab) ""
670 proc tixComboBox:EntKeyPress {w} {
673 if {!$data(-editable)} {
676 if [tixStrEq $data(-state) disabled] {
682 tixComboBox:ClearListboxSelection $w
683 tixComboBox:SetSelection $w [$data(w:entry) get] 0 0
689 #----------------------------------------------------------------------
691 proc tixComboBox:HandleDirKey {w dir} {
694 if [tixComboBox:CheckListboxSelection $w] {
697 tkListboxUpDown $data(w:listbox) -1
698 set data(curIndex) [lindex [$data(w:listbox) curselection] 0]
699 tixComboBox:SetSelectionFromListbox $w
702 tkListboxUpDown $data(w:listbox) 1
703 set data(curIndex) [lindex [$data(w:listbox) curselection] 0]
704 tixComboBox:SetSelectionFromListbox $w
707 $data(w:listbox) yview scroll -1 pages
710 $data(w:listbox) yview scroll 1 pages
714 # There wasn't good selection in the listbox.
716 tixComboBox:SetSelectionFromListbox $w
720 proc tixComboBox:Invoke {w} {
723 tixComboBox:SetValue $w $data(-selection)
724 if ![winfo exists $w] {
728 if {$data(-history)} {
729 tixComboBox:addhistory $w $data(-value)
732 $data(w:entry) selection from 0
733 $data(w:entry) selection to end
734 $data(w:entry) icursor end
737 #----------------------------------------------------------------------
738 # MAINTAINING THE -VALUE
739 #----------------------------------------------------------------------
740 proc tixComboBox:SetValue {w newValue {noUpdate 0} {updateEnt 1}} {
743 if {$data(-validatecmd) != ""} {
744 set data(-value) [tixEvalCmdBinding $w $data(-validatecmd) "" $newValue]
746 set data(-value) $newValue
750 tixVariable:UpdateVariable $w
754 if {!$data(-editable)} {
755 $data(w:entry) delete 0 end
756 $data(w:entry) insert 0 $data(-value)
760 if {!$data(-disablecallback) && $data(-command) != ""} {
761 if {![info exists data(varInited)]} {
763 set bind(%V) $data(-value)
765 tixEvalCmdBinding $w $data(-command) bind $data(-value)
766 if ![winfo exists $w] {
767 # The user destroyed the window!
773 set data(-selection) $data(-value)
775 tixSetEntry $data(w:entry) $data(-value)
777 if {$data(-anchor) == "e"} {
778 tixComboBox:EntryAlignEnd $w
783 # markSel: should the all the text in the entry be highlighted?
785 proc tixComboBox:SetSelection {w value {markSel 1} {setent 1}} {
789 tixSetEntry $data(w:entry) $value
791 set data(-selection) $value
793 if {$data(-selectmode) == "browse"} {
795 $data(w:entry) selection range 0 end
797 if {$data(-browsecmd) != ""} {
799 set bind(%V) [$data(w:entry) get]
800 tixEvalCmdBinding $w $data(-browsecmd) bind [$data(w:entry) get]
803 tixComboBox:SetValue $w $value 0 0
807 proc tixComboBox:ClearListboxSelection {w} {
810 $data(w:listbox) selection clear 0 end
813 proc tixComboBox:UpdateListboxSelection {w index} {
817 $data(w:listbox) selection set $index
818 $data(w:listbox) selection anchor $index
823 proc tixComboBox:Cancel {w} {
826 tixSetEntry $data(w:entry) $data(-value)
827 tixComboBox:SetSelection $w $data(-value)
829 if {"x[tixComboBox:LbGetSelection $w]" != "x$data(-selection)"} {
830 tixComboBox:ClearListboxSelection $w
834 proc tixComboBox:flash {w} {
835 tixComboBox:BlinkEntry $w
838 # Make the entry blink when the user selects a choice
840 proc tixComboBox:BlinkEntry {w} {
843 if {![info exists data(entryBlacken)]} {
844 set old_bg [$data(w:entry) cget -bg]
845 set old_fg [$data(w:entry) cget -fg]
847 $data(w:entry) config -fg $old_bg
848 $data(w:entry) config -bg $old_fg
850 set data(entryBlacken) 1
851 after 50 tixComboBox:RestoreBlink $w [list $old_bg] [list $old_fg]
855 proc tixComboBox:RestoreBlink {w old_bg old_fg} {
858 if {[info exists data(w:entry)] && [winfo exists $data(w:entry)]} {
859 $data(w:entry) config -fg $old_fg
860 $data(w:entry) config -bg $old_bg
863 if [info exists data(entryBlacken)] {
864 unset data(entryBlacken)
868 #----------------------------------------
869 # Handle events inside the list box
870 #----------------------------------------
872 proc tixComboBox:LbIndex {w {flag ""}} {
875 set sel [lindex [$data(w:listbox) curselection] 0]
879 if {$flag == "emptyOK"} {
887 #----------------------------------------------------------------------
891 #----------------------------------------------------------------------
892 proc tixComboBox:GoState-0 {w} {
896 proc tixComboBox:GoState-1 {w} {
902 proc tixComboBox:GoState-2 {w} {
907 proc tixComboBox:GoState-3 {w} {
911 tixComboBox:Popdown $w
914 proc tixComboBox:GoState-4 {w} {
917 tixComboBox:Ungrab $w
919 tixComboBox:Cancel $w
921 tixComboBox:Invoke $w
923 tixComboBox:GoState 0 $w
926 proc tixComboBox:GoState-5 {w x y X Y} {
929 tixComboBox:LbSelect $w $x $y $X $Y
932 proc tixComboBox:GoState-6 {w x y X Y} {
935 tixComboBox:Popdown $w
937 if [tixWithinWindow $data(w:shell) $X $Y] {
943 tixComboBox:GoState 4 $w
946 proc tixComboBox:GoState-7 {w} {
949 tixComboBox:Popdown $w
953 if {$tkPriv(afterId) != ""} {
959 tixComboBox:GoState 4 $w
962 proc tixComboBox:GoState-9 {w x y X Y} {
966 tkButtonUp $data(w:arrow)
968 tixComboBox:GoState 5 $w $x $y $X $Y
971 proc tixComboBox:GoState-10 {w dir} {
975 if {![tixComboBox:CheckListboxSelection $w]} {
976 # There wasn't good selection in the listbox.
978 tixComboBox:SetSelectionFromListbox $w
981 tixComboBox:GoState 2 $w
984 proc tixComboBox:GoState-11 {w dir} {
987 tixComboBox:HandleDirKey $w $dir
989 tixComboBox:GoState 2 $w
992 proc tixComboBox:GoState-12 {w} {
996 tkButtonUp $data(w:arrow)
999 tixComboBox:GoState 2 $w
1002 proc tixComboBox:GoState-13 {w} {
1007 if {$tkPriv(afterId) != ""} {
1011 tixComboBox:GoState 2 $w
1014 proc tixComboBox:GoState-14 {w} {
1017 tixComboBox:Invoke $w
1018 tixComboBox:GoState 0 $w
1021 proc tixComboBox:GoState-15 {w} {
1024 tixComboBox:Popdown $w
1026 tixComboBox:GoState 4 $w
1029 proc tixComboBox:GoState-16 {w} {
1032 tixComboBox:Popdown $w
1033 tixComboBox:Cancel $w
1035 tixComboBox:GoState 4 $w
1038 proc tixComboBox:GoState-17 {w} {
1041 tixComboBox:Cancel $w
1042 tixComboBox:GoState 0 $w
1045 proc tixComboBox:GoState-19 {w} {
1048 if {"x$data(-selection)" != "x$data(-value)"} {
1053 tixComboBox:Popdown $w
1056 #----------------------------------------------------------------------
1057 # Non-dropdown states
1058 #----------------------------------------------------------------------
1059 proc tixComboBox:GoState-n0 {w} {
1063 proc tixComboBox:GoState-n1 {w} {
1066 tixComboBox:Invoke $w
1067 tixComboBox:GoState n0 $w
1070 proc tixComboBox:GoState-n3 {w dir} {
1073 tixComboBox:HandleDirKey $w $dir
1074 tixComboBox:GoState n0 $w
1077 proc tixComboBox:GoState-n4 {w} {
1080 tixComboBox:Cancel $w
1081 tixComboBox:GoState n0 $w
1084 proc tixComboBox:GoState-n6 {w x y X Y} {
1087 tixComboBox:LbSelect $w $x $y $X $Y
1090 #----------------------------------------------------------------------
1091 # General State Manipulation
1092 #----------------------------------------------------------------------
1093 proc tixComboBox:GoState {s w args} {
1096 tixComboBox:SetState $w $s
1097 eval tixComboBox:GoState-$s $w $args
1100 proc tixComboBox:SetState {w s} {
1103 # catch {puts [info level -2]}
1104 # puts "setting state $data(state) --> $s"
1108 proc tixComboBox:StateError {w} {
1111 # error "wrong state $data(state)"
1114 #----------------------------------------------------------------------
1116 #----------------------------------------------------------------------
1118 # Set a selection if there isn't one. Returns true if there was already
1119 # a good selection inside the listbox
1121 proc tixComboBox:CheckListboxSelection {w} {
1124 if {[$data(w:listbox) curselection] == ""} {
1125 if {$data(curIndex) == ""} {
1126 set data(curIndex) 0
1129 $data(w:listbox) activate $data(curIndex)
1130 $data(w:listbox) selection clear 0 end
1131 $data(w:listbox) selection set $data(curIndex)
1132 $data(w:listbox) see $data(curIndex)
1139 proc tixComboBox:SetSelectionFromListbox {w} {
1142 set string [$data(w:listbox) get $data(curIndex)]
1143 tixComboBox:SetSelection $w $string
1144 tixComboBox:UpdateListboxSelection $w $data(curIndex)
1147 proc tixComboBox:LbGetSelection {w} {
1149 set index [tixComboBox:LbIndex $w emptyOK]
1152 return [$data(w:listbox) get $index]
1158 proc tixComboBox:LbSelect {w x y X Y} {
1161 set index [tixComboBox:LbIndex $w emptyOK]
1163 set index [$data(w:listbox) nearest $y]
1167 if {"x[focus -lastfor $data(w:entry)]" != "x$data(w:entry)" &&
1168 "x[focus -lastfor $data(w:entry)]" != "x$data(w:listbox)"} {
1169 focus $data(w:entry)
1172 set string [$data(w:listbox) get $index]
1173 tixComboBox:SetSelection $w $string
1175 tixComboBox:UpdateListboxSelection $w $index
1179 #----------------------------------------------------------------------
1181 #----------------------------------------------------------------------
1182 proc tixComboBox:CrossBtn {w} {
1185 $data(w:entry) delete 0 end
1186 tixComboBox:ClearListboxSelection $w
1187 tixComboBox:SetSelection $w ""
1190 #--------------------------------------------------
1191 # Popping up list shell
1192 #--------------------------------------------------
1194 # Popup the listbox and grab
1197 proc tixComboBox:Popup {w} {
1201 if {![winfo ismapped $data(w:root)]} {
1205 #---------------------------------------------------------------------
1208 if {$data(-listcmd) != ""} {
1209 # This option allows the user to fill in the listbox on demand
1211 tixEvalCmdBinding $w $data(-listcmd)
1214 # calculate the size
1215 set y [winfo rooty $data(w:entry)]
1216 incr y [winfo height $data(w:entry)]
1219 set bd [$data(w:shell) cget -bd]
1220 # incr bd [$data(w:shell) cget -highlightthickness]
1221 set height [expr [winfo reqheight $data(w:slistbox)] + 2*$bd]
1223 set x1 [winfo rootx $data(w:entry)]
1224 if {$data(-listwidth) == ""} {
1225 if [winfo ismapped $data(w:arrow)] {
1226 set x2 [winfo rootx $data(w:arrow)]
1228 incr x2 [winfo width $data(w:arrow)]
1229 set width [expr "$x2 - $x1"]
1231 set width [winfo width $data(w:entry)]
1232 set x2 [expr $x1 + $width]
1235 set width [winfo width $data(w:entry)]
1236 set x2 [expr $x1 + $width]
1239 set width $data(-listwidth)
1240 set x2 [expr $x1 + $width]
1243 set reqwidth [winfo reqwidth $data(w:shell)]
1244 if {$reqwidth < $width} {
1247 if {$reqwidth > [expr $width *3]} {
1248 set reqwidth [expr $width *3]
1250 if {$reqwidth > [winfo vrootwidth .]} {
1251 set reqwidth [winfo vrootwidth .]
1257 # If the listbox is too far right, pull it back to the left
1259 set scrwidth [winfo vrootwidth .]
1260 if {$x2 > $scrwidth} {
1261 set x1 [expr $scrwidth - $width]
1264 # If the listbox is too far left, pull it back to the right
1270 # If the listbox is below bottom of screen, put it upwards
1272 set scrheight [winfo vrootheight .]
1273 set bottom [expr $y+$height]
1274 if {$bottom > $scrheight} {
1275 set y [expr $y-$height-[winfo height $data(w:entry)]-5]
1278 # OK , popup the shell
1281 wm geometry $data(w:shell) $reqwidth\x$height+$x1+$y
1282 if {$tcl_platform(platform) == "windows"} {
1285 wm deiconify $data(w:shell)
1286 if {$tcl_platform(platform) == "windows"} {
1290 raise $data(w:shell)
1291 focus $data(w:entry)
1297 proc tixComboBox:SetCursor {w cursor} {
1300 $w config -cursor $cursor
1303 proc tixComboBox:Popdown {w} {
1306 wm withdraw $data(w:shell)
1307 tixComboBox:SetCursor $w ""
1310 # Grab the server so that user cannot move the windows around
1311 proc tixComboBox:Grab {w} {
1314 tixComboBox:SetCursor $w arrow
1316 # We catch here because grab may fail under a lot of circumstances
1317 # Just don't want to break the code ...
1320 tixPushGrab -global $data(w:root)
1323 tixPushGrab $data(w:root)
1329 proc tixComboBox:Ungrab {w} {
1342 #----------------------------------------------------------------------
1344 #----------------------------------------------------------------------
1345 # The following two routines can emulate a "right align mode" for the
1346 # entry in the combo box.
1348 proc tixComboBox:EntryAlignEnd {w} {
1350 $data(w:entry) xview end
1354 proc tixComboBox:Destructor {w} {
1357 tixUnsetMegaWidget $data(w:entry)
1358 tixVariable:DeleteVariable $w
1360 # Chain this to the superclass
1362 tixChainMethod $w Destructor
1366 #----------------------------------------------------------------------
1368 #----------------------------------------------------------------------
1370 proc tixComboBox:config-state {w value} {
1372 catch {if {"x[$data(w:arrow) cget -state]" == "x$value"} {
1375 if [info exists a] {
1379 catch {$data(w:arrow) config -state $value}
1380 catch {$data(w:tick) config -state $value}
1381 catch {$data(w:cross) config -state $value}
1382 catch {$data(w:slistbox) config -state $value}
1384 if ![string compare $value normal] {
1385 set fg [$data(w:arrow) cget -fg]
1386 set entryFg $data(entryfg)
1387 set lbSelFg [lindex [$data(w:listbox) config -selectforeground] 3]
1388 set lbSelBg [lindex [$data(w:listbox) config -selectbackground] 3]
1389 set entrySelFg [lindex [$data(w:entry) config -selectforeground] 3]
1390 set entrySelBg [lindex [$data(w:entry) config -selectbackground] 3]
1392 set fg [$data(w:arrow) cget -disabledforeground]
1393 set entryFg $data(-disabledforeground)
1394 set lbSelFg $entryFg
1395 set lbSelBg [$data(w:listbox) cget -bg]
1396 set entrySelFg $entryFg
1397 set entrySelBg [$data(w:entry) cget -bg]
1399 if [string compare $fg ""] {
1400 $data(w:label) config -fg $fg
1401 $data(w:listbox) config -fg $fg -selectforeground $lbSelFg \
1402 -selectbackground $lbSelBg
1404 $data(w:entry) config -fg $entryFg -selectforeground $entrySelFg \
1405 -selectbackground $entrySelBg
1407 if ![string compare $value normal] {
1408 if {$data(-editable)} {
1409 $data(w:entry) config -state normal
1411 $data(w:entry) config -takefocus 1
1413 if {$data(-editable)} {
1414 $data(w:entry) config -state disabled
1416 $data(w:entry) config -takefocus 0
1420 proc tixComboBox:config-value {w value} {
1423 tixComboBox:SetValue $w $value
1425 set data(-selection) $value
1427 if {"x[tixComboBox:LbGetSelection $w]" != "x$value"} {
1428 tixComboBox:ClearListboxSelection $w
1432 proc tixComboBox:config-selection {w value} {
1435 tixComboBox:SetSelection $w $value
1437 if {"x[tixComboBox:LbGetSelection $w]" != "x$value"} {
1438 tixComboBox:ClearListboxSelection $w
1442 proc tixComboBox:config-variable {w arg} {
1445 if [tixVariable:ConfigVariable $w $arg] {
1446 # The value of data(-value) is changed if tixVariable:ConfigVariable
1448 set data(-selection) $data(-value)
1449 tixComboBox:SetValue $w $data(-value) 1
1452 unset data(varInited)
1454 set data(-variable) $arg
1458 #----------------------------------------------------------------------
1460 #----------------------------------------------------------------------
1461 proc tixComboBox:align {w args} {
1464 if {$data(-anchor) == "e"} {
1465 tixComboBox:EntryAlignEnd $w
1469 proc tixComboBox:addhistory {w value} {
1472 tixComboBox:insert $w 0 $value
1473 $data(w:listbox) selection clear 0 end
1475 if {$data(-prunehistory)} {
1476 # Prune from the end
1478 set max [$data(w:listbox) size]
1482 for {set i [expr $max -1]} {$i >= 1} {incr i -1} {
1483 if {"x[$data(w:listbox) get $i]" == "x$value"} {
1484 $data(w:listbox) delete $i
1491 proc tixComboBox:appendhistory {w value} {
1494 tixComboBox:insert $w end $value
1495 $data(w:listbox) selection clear 0 end
1497 if {$data(-prunehistory)} {
1498 # Prune from the end
1500 set max [$data(w:listbox) size]
1504 for {set i [expr $max -2]} {$i >= 0} {incr i -1} {
1505 if {"x[$data(w:listbox) get $i]" == "x$value"} {
1506 $data(w:listbox) delete $i
1513 proc tixComboBox:insert {w index newitem} {
1516 $data(w:listbox) insert $index $newitem
1518 if {$data(-history) && $data(-historylimit) != ""} {
1519 if {"x[$data(w:listbox) size]" == "x$data(-historylimit)"} {
1520 $data(w:listbox) delete 0
1525 proc tixComboBox:pick {w index} {
1528 $data(w:listbox) activate $index
1529 $data(w:listbox) selection clear 0 end
1530 $data(w:listbox) selection set active
1531 $data(w:listbox) see active
1532 set text [$data(w:listbox) get $index]
1534 tixComboBox:SetValue $w $text
1536 set data(curIndex) $index
1539 proc tixComboBox:invoke {w} {
1540 tixComboBox:Invoke $w
1543 proc tixComboBox:popdown {w} {
1546 if {$data(-dropdown)} {
1547 tixComboBox:Popdown $w