1 # ui-combobox.tcl --
2 #
3 # Defines a combobox widget. Copies of similar code are present
4 # in other parts of mash.
5 #
6 # Copyright (c) 1998-2002 The Regents of the University of California.
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are met:
11 #
12 # A. Redistributions of source code must retain the above copyright notice,
13 # this list of conditions and the following disclaimer.
14 # B. Redistributions in binary form must reproduce the above copyright notice,
15 # this list of conditions and the following disclaimer in the documentation
16 # and/or other materials provided with the distribution.
17 # C. Neither the names of the copyright holders nor the names of its
18 # contributors may be used to endorse or promote products derived from this
19 # software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
25 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 import TextEntry
33
34 # Implements a combobox widget that consists of an entry widget
35 # and a menu that can be used to quickly enter one of several
36 # defaults.
37 Class Combobox
38
39 Combobox set arrow [image create bitmap -data {
40 \#define arrow_width 14
41 \#define arrow_height 14
42 static char arrow_bits[] = {
43 0x00, 0x00, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xe0, 0x01, 0xfc, 0x0f,
44 0xf8, 0x07, 0xf0, 0x03, 0xe0, 0x01, 0xc0, 0x00, 0x00, 0x00, 0xfe, 0x1f,
45 0xfe, 0x1f, 0x00, 0x00};
46 }]
47
48 # Creates a new Combobox widget in a Tk window <i>w</i>.
49 # The initial value in the Combobox is given by <i>value</i>.
50 # When a new value is entered, the tcl procedure <i>cmd</i> is
51 # called to validate the new value (as with a TextEntry object).
52 # All arguments after <i>cmd</i> are default values available in
53 # the menu.
54 Combobox public init {w value cmd args} {
55 $self instvar win_ entry_
56 $class instvar arrow
57
58 set win_ $w
59 frame $w
60 set entry_ [new TextEntry $cmd $w.entry $value]
61 pack $w.entry -side left -fill x -expand yes
62
63 menubutton $w.b -image $arrow -menu $w.b.m -indicatoron no \
64 -relief raised -bd 2
65 pack $w.b
66 menu $w.b.m
67 foreach a $args {
68 $w.b.m add command -label $a -command "$self set \"$a\""
69 }
70 }
71
72 # Destroys this widget.
73 Combobox public destroy {} {
74 $self instvar win_
75 destroy $win_
76 }
77
78 # Sets the value in this widget to <i>value</i>
79 Combobox public set {value} {
80 #puts "Combobox setting value to $value"
81 # $self instvar win_
82 # set e $win_.entry
83 # $e delete 0 end
84 # $e insert 0 $value
85 $self instvar entry_
86 $entry_ set-value $value
87 }
88
89 # Gets the string that is currently entered in this widget.
90 Combobox public get {} {
91 $self instvar entry_
92 #puts "Combobox returning [$entry_ entry-value]"
93 return [$entry_ entry-value]
94 }
95
96 # Enables this widget so that the value can be changed and the
97 # menu is active.
98 Combobox public enable {} {
99 $self instvar win_
100 $win_.b configure -state normal
101 $win_.entry configure -state normal
102 }
103
104 # Disables this widget so that the value cannot be changed either
105 # by typing or via the menu.
106 Combobox public disable {} {
107 $self instvar win_
108 $win_.b configure -state disabled
109 $win_.entry configure -state disabled
110 }
111
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.