1 # toolbar.tcl - Handle layout for a toolbar.
2 # Copyright (C) 1997 Cygnus Solutions.
3 # Written by Tom Tromey <tromey@cygnus.com>.
5 # This holds global state for this module.
6 defarray TOOLBAR_state {
14 proc TOOLBAR_button_enter {w} {
17 #save older relief (it covers buttons that
18 #interacte like checkbuttons)
19 set TOOLBAR_state(relief) [$w cget -relief]
21 if {[$w cget -state] != "disabled"} then {
23 if {$TOOLBAR_state(button) == $w} then {
34 #store last action to synchronize operations
35 set TOOLBAR_state(last) enter
36 set TOOLBAR_state(window) $w
39 proc TOOLBAR_button_leave {w} {
41 if {[$w cget -state] != "disabled"} then {
42 $w configure -state normal
45 #restore original relief
47 $TOOLBAR_state(window) == $w
48 && $TOOLBAR_state(last) == "enter"
50 $w configure -relief $TOOLBAR_state(relief)
52 $w configure -relief flat
55 set TOOLBAR_state(window) ""
56 #store last action to synch operations (enter->leave)
57 set TOOLBAR_state(last) leave
60 proc TOOLBAR_button_down {w} {
62 if {[$w cget -state] != "disabled"} then {
63 set TOOLBAR_state(button) $w
64 $w configure -relief sunken
68 proc TOOLBAR_button_up {w} {
70 if {$w == $TOOLBAR_state(button)} then {
71 set TOOLBAR_state(button) ""
73 #restore original relief
74 $w configure -relief $TOOLBAR_state(relief)
76 if {$TOOLBAR_state(window) == $w
77 && [$w cget -state] != "disabled"} then {
79 #SN does the toolbar bindings using "+" so that older
80 #bindings don't disapear. So no need to invoke the command.
81 #other applications should do the same so that we can delete
84 if {! [array exists sn_options]} {
86 uplevel \#0 [list $w invoke]
88 if {[winfo exists $w]} then {
89 if {[$w cget -state] != "disabled"} then {
90 $w configure -state normal
93 # HOWEVER, if the pointer is still over the button, and it
94 # is enabled, then raise it again.
96 if {[string compare [winfo containing \
98 [winfo pointery $w]] $w] == 0} {
99 $w configure -relief raised
105 # Set up toolbar bindings.
106 proc TOOLBAR_maybe_init {} {
108 if {! $TOOLBAR_state(initialized)} then {
109 set TOOLBAR_state(initialized) 1
111 # We can't put our bindings onto the widget (and then use "break"
112 # to avoid the class bindings) because that interacts poorly with
114 bind ToolbarButton <Enter> [list TOOLBAR_button_enter %W]
115 bind ToolbarButton <Leave> [list TOOLBAR_button_leave %W]
116 bind ToolbarButton <1> [list TOOLBAR_button_down %W]
117 bind ToolbarButton <ButtonRelease-1> [list TOOLBAR_button_up %W]
121 #Allows changing options of a toolbar button from the application
122 #especially the relief value
123 proc TOOLBAR_command {w args} {
126 set len [llength $args]
127 for {set i 0} {$i < $len} {incr i} {
128 set cmd [lindex $args $i]
133 set TOOLBAR_state(relief) [lindex $args $i]
134 $w configure $cmd [lindex $args $i]
139 set TOOLBAR_state(window) [lindex $args $i]
142 #normal widget options
144 $w configure $cmd [lindex $args $i]
150 # Pass this proc a frame and some children of the frame. It will put
151 # the children into the frame so that they look like a toolbar.
152 # Children are added in the order they are listed. If a child's name
153 # is "-", then the appropriate type of separator is entered instead.
154 # If a child's name is "--" then all remaining children will be placed
155 # on the right side of the window.
157 # For non-flat mode, each button must display an image, and this image
158 # must have a twin. The primary (raised) image's name must end in
159 # "u", and the depressed image's name must end in "d". Eg the edit
160 # images should be called "editu" and "editd". There's no doubt that
163 # If you want to add a button that doesn't have an image (or whose
164 # image doesn't have a twin), you must wrap it in a frame.
166 # FIXME: someday, write a `toolbar button' widget that handles the
167 # image mess invisibly.
168 proc standard_toolbar {frame args} {
171 # For now, there are two different layouts, depending on which kind
172 # of icons we're using. This is just a test feature and will be
173 # eliminated once we decide on an icon style.
177 # We reserve column 0 for some padding.
179 if {$tcl_platform(platform) == "windows"} then {
180 # See below to understand this.
185 # This is set if we see "--" and thus the filling happens in the
189 foreach button $args {
190 grid columnconfigure $frame $column -weight 0
192 if {$button == "-"} then {
194 set f [frame $frame.[gensym] -borderwidth 1 -width 2 -relief sunken]
195 grid $f -row $row -column $column -sticky ns${sticky} -padx 4
196 } elseif {$button == "--"} then {
197 # Everything after this is put on the right. We do this by
198 # adding a column that sucks up all the space.
201 grid columnconfigure $frame $column -weight 1 -minsize 7
202 } elseif {[winfo class $button] != "Button"} then {
203 # Something other than a button. Just put it into the frame.
204 grid $button -row $row -column $column -sticky $sticky -pady 2
207 # FIXME: does Windows allow focus traversal? For now we're
208 # just turning it off.
209 $button configure -takefocus 0 -highlightthickness 0 \
210 -relief flat -borderwidth 1
211 grid $button -row $row -column $column -sticky $sticky -pady 2
213 # Make sure the button acts the way we want, not the default Tk
215 set index [lsearch -exact [bindtags $button] Button]
216 bindtags $button [lreplace [bindtags $button] $index $index \
223 # On Unix, it looks a little more natural to have a raised toolbar.
224 # On Windows the toolbar is flat, but there is a horizontal
225 # separator between the toolbar and the menubar. On both platforms
226 # we provide some space to the left of the leftmost widget.
227 grid columnconfigure $frame 0 -minsize 7 -weight 0
229 if {$tcl_platform(platform) == "windows"} then {
230 $frame configure -borderwidth 0 -relief flat
231 set name $frame.[gensym]
232 frame $name -height 2 -borderwidth 1 -relief sunken
233 grid $name -row 0 -column 0 -columnspan $column -pady 1 -sticky ew
235 $frame configure -borderwidth 2 -relief raised
238 if {! $center_fill} then {
239 # The rightmost column sucks up the extra space.
241 grid columnconfigure $frame $column -weight 1