2 # Sizegrip widget bindings.
4 # Dragging a sizegrip widget resizes the containing toplevel.
6 # NOTE: the sizegrip widget must be in the lower right hand corner.
9 switch -- [tk windowingsystem
] {
12 option add
*TSizegrip.cursor
[ttk
::cursor seresize
]
15 # Aqua sizegrips use default Arrow cursor.
19 namespace eval ttk
::sizegrip {
35 bind TSizegrip
<ButtonPress-1
> { ttk
::sizegrip::Press %W
%X
%Y
}
36 bind TSizegrip
<B1-Motion
> { ttk
::sizegrip::Drag %W
%X
%Y
}
37 bind TSizegrip
<ButtonRelease-1
> { ttk
::sizegrip::Release %W
%X
%Y
}
39 proc ttk
::sizegrip::Press {W X Y
} {
42 if {[$W instate disabled
]} { return }
44 set top
[winfo toplevel $W]
46 # If the toplevel is not resizable then bail
47 foreach {State
(resizeX
) State
(resizeY
)} [wm resizable
$top] break
48 if {!$State(resizeX
) && !$State(resizeY
)} {
53 # If a negative X or Y position was specified for [wm geometry],
54 # just bail out -- there's no way to handle this cleanly.
56 if {[scan [wm geometry
$top] "%dx%d+%d+%d" width height x y
] != 4} {
60 # Account for gridded geometry:
62 set grid [wm grid $top]
63 if {[llength $grid]} {
64 set State
(widthInc
) [lindex $grid 2]
65 set State
(heightInc
) [lindex $grid 3]
67 set State
(widthInc
) [set State
(heightInc
) 1]
70 set State
(toplevel) $top
73 set State
(width
) $width
74 set State
(height
) $height
80 proc ttk
::sizegrip::Drag {W X Y
} {
82 if {!$State(pressed
)} { return }
85 if {$State(resizeX
)} {
86 set w
[expr {$w + ($X - $State(pressX
))/$State(widthInc
)}]
88 if {$State(resizeY
)} {
89 set h
[expr {$h + ($Y - $State(pressY
))/$State(heightInc
)}]
91 if {$w <= 0} { set w
1 }
92 if {$h <= 0} { set h
1 }
93 set x
$State(x
) ; set y
$State(y
)
94 wm geometry
$State(toplevel) ${w
}x
${h
}+${x
}+${y
}
97 proc ttk
::sizegrip::Release {W X Y
} {