2 # $Id: sizegrip.tcl,v 1.1.4.2 2010/08/26 02:06:10 hobbs Exp $
4 # 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 switch -- [tk windowingsystem
] {
14 option add
*TSizegrip.cursor
[ttk
::cursor seresize
]
17 # Aqua sizegrips use default Arrow cursor.
21 namespace eval ttk
::sizegrip {
37 bind TSizegrip
<ButtonPress-1
> { ttk
::sizegrip::Press %W
%X
%Y
}
38 bind TSizegrip
<B1-Motion
> { ttk
::sizegrip::Drag %W
%X
%Y
}
39 bind TSizegrip
<ButtonRelease-1
> { ttk
::sizegrip::Release %W
%X
%Y
}
41 proc ttk
::sizegrip::Press {W X Y
} {
44 if {[$W instate disabled
]} { return }
46 set top
[winfo toplevel $W]
48 # If the toplevel is not resizable then bail
49 foreach {State
(resizeX
) State
(resizeY
)} [wm resizable
$top] break
50 if {!$State(resizeX
) && !$State(resizeY
)} {
55 # If a negative X or Y position was specified for [wm geometry],
56 # just bail out -- there's no way to handle this cleanly.
58 if {[scan [wm geometry
$top] "%dx%d+%d+%d" width height x y
] != 4} {
62 # Account for gridded geometry:
64 set grid [wm grid $top]
65 if {[llength $grid]} {
66 set State
(widthInc
) [lindex $grid 2]
67 set State
(heightInc
) [lindex $grid 3]
69 set State
(widthInc
) [set State
(heightInc
) 1]
72 set State
(toplevel) $top
75 set State
(width
) $width
76 set State
(height
) $height
82 proc ttk
::sizegrip::Drag {W X Y
} {
84 if {!$State(pressed
)} { return }
87 if {$State(resizeX
)} {
88 set w
[expr {$w + ($X - $State(pressX
))/$State(widthInc
)}]
90 if {$State(resizeY
)} {
91 set h
[expr {$h + ($Y - $State(pressY
))/$State(heightInc
)}]
93 if {$w <= 0} { set w
1 }
94 if {$h <= 0} { set h
1 }
95 set x
$State(x
) ; set y
$State(y
)
96 wm geometry
$State(toplevel) ${w
}x
${h
}+${x
}+${y
}
99 proc ttk
::sizegrip::Release {W X Y
} {