3 # This file defines the default bindings for Tk panedwindow widgets and
4 # provides procedures that help in implementing those bindings.
6 # RCS: @(#) $Id: panedwindow.tcl,v 1.6.2.4 2006/01/25 18:21:41 dgp Exp $
9 bind Panedwindow
<Button-1
> { ::tk::panedwindow::MarkSash %W
%x
%y
1 }
10 bind Panedwindow
<Button-2
> { ::tk::panedwindow::MarkSash %W
%x
%y
0 }
12 bind Panedwindow
<B1-Motion
> { ::tk::panedwindow::DragSash %W
%x
%y
1 }
13 bind Panedwindow
<B2-Motion
> { ::tk::panedwindow::DragSash %W
%x
%y
0 }
15 bind Panedwindow
<ButtonRelease-1
> {::tk::panedwindow::ReleaseSash %W
1}
16 bind Panedwindow
<ButtonRelease-2
> {::tk::panedwindow::ReleaseSash %W
0}
18 bind Panedwindow
<Motion
> { ::tk::panedwindow::Motion %W
%x
%y
}
20 bind Panedwindow
<Leave
> { ::tk::panedwindow::Leave %W
}
22 # Initialize namespace
23 namespace eval ::tk::panedwindow {}
25 # ::tk::panedwindow::MarkSash --
27 # Handle marking the correct sash for possible dragging
31 # x widget local x coord
32 # y widget local y coord
33 # proxy whether this should be a proxy sash
37 proc ::tk::panedwindow::MarkSash {w x y proxy
} {
38 if {[$w cget
-opaqueresize]} { set proxy
0 }
39 set what
[$w identify
$x $y]
40 if { [llength $what] == 2 } {
41 foreach {index which
} $what break
42 if { !$::tk_strictMotif ||
$which eq
"handle" } {
43 if {!$proxy} { $w sash mark
$index $x $y }
44 set ::tk::Priv(sash
) $index
45 foreach {sx sy
} [$w sash coord
$index] break
46 set ::tk::Priv(dx
) [expr {$sx-$x}]
47 set ::tk::Priv(dy
) [expr {$sy-$y}]
48 # Do this to init the proxy location
49 DragSash
$w $x $y $proxy
54 # ::tk::panedwindow::DragSash --
56 # Handle dragging of the correct sash
60 # x widget local x coord
61 # y widget local y coord
62 # proxy whether this should be a proxy sash
66 proc ::tk::panedwindow::DragSash {w x y proxy
} {
67 if {[$w cget
-opaqueresize]} { set proxy
0 }
68 if { [info exists
::tk::Priv(sash
)] } {
71 [expr {$x+$::tk::Priv(dx
)}] [expr {$y+$::tk::Priv(dy
)}]
73 $w sash
place $::tk::Priv(sash
) \
74 [expr {$x+$::tk::Priv(dx
)}] [expr {$y+$::tk::Priv(dy
)}]
79 # ::tk::panedwindow::ReleaseSash --
81 # Handle releasing of the sash
85 # proxy whether this should be a proxy sash
89 proc ::tk::panedwindow::ReleaseSash {w proxy
} {
90 if {[$w cget
-opaqueresize]} { set proxy
0 }
91 if { [info exists
::tk::Priv(sash
)] } {
93 foreach {x y
} [$w proxy coord
] break
94 $w sash
place $::tk::Priv(sash
) $x $y
97 unset ::tk::Priv(sash
) ::tk::Priv(dx
) ::tk::Priv(dy
)
101 # ::tk::panedwindow::Motion --
103 # Handle motion on the widget. This is used to change the cursor
104 # when the user moves over the sash area.
108 # x widget local x coord
109 # y widget local y coord
111 # May change the cursor. Sets up a timer to verify that we are still
114 proc ::tk::panedwindow::Motion {w x y
} {
116 set id
[$w identify
$x $y]
117 if {([llength $id] == 2) && \
118 (!$::tk_strictMotif ||
[lindex $id 1] eq
"handle")} {
119 if { ![info exists Priv
($w,panecursor
)] } {
120 set Priv
($w,panecursor
) [$w cget
-cursor]
121 if { [$w cget
-sashcursor] eq
"" } {
122 if { [$w cget
-orient] eq
"horizontal" } {
123 $w configure
-cursor sb_h_double_arrow
125 $w configure
-cursor sb_v_double_arrow
128 $w configure
-cursor [$w cget
-sashcursor]
130 if {[info exists Priv
($w,pwAfterId
)]} {
131 after cancel
$Priv($w,pwAfterId
)
133 set Priv
($w,pwAfterId
) [after 150 \
134 [list ::tk::panedwindow::Cursor $w]]
138 if { [info exists Priv
($w,panecursor
)] } {
139 $w configure
-cursor $Priv($w,panecursor
)
140 unset Priv
($w,panecursor
)
144 # ::tk::panedwindow::Cursor --
146 # Handles returning the normal cursor when we are no longer over the
147 # sash area. This needs to be done this way, because the panedwindow
148 # won't see Leave events when the mouse moves from the sash to a
149 # paned child, although the child does receive an Enter event.
154 # May restore the default cursor, or schedule a timer to do it.
156 proc ::tk::panedwindow::Cursor {w
} {
158 # Make sure to check window existence in case it is destroyed.
159 if {[info exists Priv
($w,panecursor
)] && [winfo exists
$w]} {
160 if {[winfo containing
[winfo pointerx
$w] [winfo pointery
$w]] eq
$w} {
161 set Priv
($w,pwAfterId
) [after 150 \
162 [list ::tk::panedwindow::Cursor $w]]
164 $w configure
-cursor $Priv($w,panecursor
)
165 unset Priv
($w,panecursor
)
166 if {[info exists Priv
($w,pwAfterId
)]} {
167 after cancel
$Priv($w,pwAfterId
)
168 unset Priv
($w,pwAfterId
)
174 # ::tk::panedwindow::Leave --
176 # Return to default cursor when leaving the pw widget.
181 # Restores the default cursor
183 proc ::tk::panedwindow::Leave {w
} {
184 if {[info exists
::tk::Priv($w,panecursor
)]} {
185 $w configure
-cursor $::tk::Priv($w,panecursor
)
186 unset ::tk::Priv($w,panecursor
)