1 # ui-mb-option.tcl --
2 #
3 # a customized menu similar to tk's option menu, but handles graphics and
4 # extensions
5 #
6 # Copyright (c) 1997-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 Class MBOptionMenu
33
34 MBOptionMenu instproc update {label value } {
35 $self instvar varN_ labelN_ type_ menu_button_
36 upvar #0 $varN_ v
37 upvar #0 $labelN_ lv
38
39 set v $value
40 set lv $label
41 case $type_ {
42 "colors" {
43 if {"$value" != ""} {
44 $menu_button_ configure \
45 -bg $value -activebackground $value -text " "
46 } else {
47 set bg [[winfo parent $menu_button_] cget -background]
48 $menu_button_ configure \
49 -bg $bg -activebackground $bg -text $label
50 }
51 }
52 "font" {
53 $menu_button_ configure -text "Abc" -font $value
54 }
55 default {
56 $menu_button_ configure -text $value
57 }
58 }
59 }
60
61 MBOptionMenu instproc new_color {} {
62 set newcolor [tk_chooseColor -title "Choose color"]
63 if {$newcolor!=""} {
64 $self add_colors $newcolor $newcolor
65 $self update $$newcolor $newcolor
66 }
67 }
68
69 MBOptionMenu instproc add_colors {label value} {
70 $self instvar menu_ font_
71
72 if {"$label" == "custom"} {
73 $menu_ add command -label $label -font $font_ \
74 -command "$self new_color"
75 } elseif {"$value" != ""} {
76 $menu_ add command -label " " -background $value \
77 -activebackground $value -font $font_ \
78 -command [list $self update $label $value]
79 } else {
80 $menu_ add command -label $label -font $font_ \
81 -command [list $self update $label $value]
82 }
83 }
84
85 MBOptionMenu instproc add_text {label value} {
86 $self instvar menu_ font_
87
88 $menu_ add command -label $label -font $font_ \
89 -command [list $self update $label $value]
90 }
91
92 MBOptionMenu instproc add_font {label value} {
93 $self instvar menu_
94
95 $menu_ add command -label "ABCabc" -font $value \
96 -command [list $self update $label $value]
97 }
98
99 # format of props:
100 # { typeoflist default index label1 value1 label2 value2 .... }
101 MBOptionMenu instproc init {w varName labelName props} {
102 upvar #0 $varName v
103 upvar #0 $labelName lv
104 $self instvar varN_ labelN_ menu_ menu_button_ type_
105
106 set varN_ $varName
107 set labelN_ $labelName
108
109 $self instvar font_
110 set font_ [$self get_option smallfont]
111
112 set menu_button_ [menubutton $w \
113 -indicatoron 0 -menu $w.menu -font $font_ \
114 -relief raised -anchor c]
115 set menu_ [menu $w.menu -tearoff 0]
116
117 set type_ [lindex $props 0]
118 set def [expr [lindex $props 1] * 2]
119 set propslist [lrange $props 2 end]
120 # DbgOut "props=$propslist"
121
122 foreach {label value} $propslist {
123 $self add_$type_ $label $value
124 }
125 set lv [lindex $props $def]
126 set v [lindex $props [expr $def + 1] ]
127 $self update $lv $v
128 }
129
130 proc mb_image_optionMenu {w varName firstValue args} {
131 global env
132
133 upvar #0 $varName var
134 set img [image create photo -format GIF -gamma 1]
135 $img read "$env(MB_BITMAPS)/red.gif" -to 0 0
136
137 if ![info exists var] {
138 set var $firstValue
139 }
140 menubutton $w -textvariable $varName -indicatoron 1 -menu $w.menu \
141 -relief raised -bd 2 -highlightthickness 2 -anchor c
142 menu $w.menu -tearoff 0
143 $w.menu add command -label $firstValue\
144 -command [list set $varName $firstValue]
145 foreach i $args {
146 $w.menu add command -image $img -command [list set $varName $i]
147 }
148 }
149
150 proc CollapseArgsList {l} {
151
152 set final { }
153
154 foreach i $l {
155 set var [lindex $i 0]
156 set value [lindex $i 3]
157 if {[string length $value] != 0} {
158 set final [concat $final $var $value]
159 }
160 }
161 DbgOut $final
162 return $final
163 }
164
165
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.