2 # $Id: sizegrip.tcl,v 1.1 2006/10/31 01:42:27 hobbs Exp $
4 # Ttk widget set -- sizegrip widget bindings.
6 # Dragging a sizegrip widget resizes the containing toplevel.
8 # NOTE: the sizegrip widget must be in the lower right hand corner.
11 option add
*TSizegrip.cursor
$::ttk::Cursors(seresize
)
13 namespace eval ttk
::sizegrip {
27 bind TSizegrip
<ButtonPress-1
> { ttk
::sizegrip::Press %W
%X
%Y
}
28 bind TSizegrip
<B1-Motion
> { ttk
::sizegrip::Drag %W
%X
%Y
}
29 bind TSizegrip
<ButtonRelease-1
> { ttk
::sizegrip::Release %W
%X
%Y
}
31 proc ttk
::sizegrip::Press {W X Y
} {
34 set top
[winfo toplevel $W]
37 # If a negative X or Y position was specified for [wm geometry],
38 # just bail out -- there's no way to handle this cleanly.
40 if {[scan [wm geometry
$top] "%dx%d+%d+%d" width height _x _y
] != 4} {
44 # Account for gridded geometry:
46 set grid [wm grid $top]
47 if {[llength $grid]} {
48 set State
(widthInc
) [lindex $grid 2]
49 set State
(heightInc
) [lindex $grid 3]
51 set State
(widthInc
) [set State
(heightInc
) 1]
54 set State
(toplevel) $top
57 set State
(width
) $width
58 set State
(height
) $height
62 proc ttk
::sizegrip::Drag {W X Y
} {
64 if {!$State(pressed
)} { return }
65 set w
[expr {$State(width
) + ($X - $State(pressX
))/$State(widthInc
)}]
66 set h
[expr {$State(height
) + ($Y - $State(pressY
))/$State(heightInc
)}]
67 if {$w <= 0} { set w
1 }
68 if {$h <= 0} { set h
1 }
69 wm geometry
$State(toplevel) ${w
}x
${h
}
72 proc ttk
::sizegrip::Release {W X Y
} {