13 namespace eval ::utils::pane {}
15 array set ::utils::pane::_data {}
21 proc ::utils::pane::Create {win pane1 pane2 width height {ratio 0.5} {orient vert}} {
23 set _data($win,1) $pane1
24 set _data($win,2) $pane2
25 set _data($win,drag) 1
27 if {[
string index $orient 0] == "h"} {
set vertical 0}
28 set _data($win,vertical) $vertical
30 set _data($win,min) 0.1
31 set _data($win,max) 0.9
33 ttk::frame $win -width $width -height $height
34 ttk::frame $win.$pane1
35 ttk::frame $win.$pane2
37 place $win.$pane1 -relx 0.5 -rely 0 -anchor n -relwidth 1.0 -relheight 0.5
38 place $win.$pane2 -relx 0.5 -rely 1 -anchor s -relwidth 1.0 -relheight 0.5
40 ttk::frame $win.pane_sash -height 2 -borderwidth 2 -relief groove \
41 -cursor sb_v_double_arrow
42 place $win.pane_sash -relx 0.5 -rely 0.5 -relwidth 1.0 -anchor c
44 ttk::frame $win.pane_grip -width 20 -height 7 -borderwidth 1 -relief solid \
45 -cursor sb_v_double_arrow
46 place $win.pane_grip -relx 0.95 -rely 0.5 -anchor c
48 place $win.$pane1 -relx 0 -rely 0.5 -anchor w -relwidth 0.5 -relheight 1.0
49 place $win.$pane2 -relx 1 -rely 0.5 -anchor e -relwidth 0.5 -relheight 1.0
51 ttk::frame $win.pane_sash -width 1 -borderwidth 1 -relief flat \
52 -cursor sb_h_double_arrow
53 place $win.pane_sash -relx 0.5 -rely 0.5 -relheight 1.0 -anchor c
55 ttk::frame $win.pane_grip -height 20 -width 7 -borderwidth 1 -relief solid \
56 -cursor sb_h_double_arrow
57 place $win.pane_grip -relx 0.5 -rely 0.95 -anchor c
65 if {$vertical} {
set c "%Y"}
else {
set c "%X"}
66 bind $win.pane_grip <ButtonPress-1> "::utils::pane::Grab $win"
67 bind $win.pane_grip <B1-Motion> "::utils::pane::Drag $win $c"
68 bind $win.pane_grip <ButtonRelease-1> "::utils::pane::Drop $win $c"
69 bind $win.pane_sash <ButtonPress-1> "::utils::pane::Grab $win"
70 bind $win.pane_sash <B1-Motion> "::utils::pane::Drag $win $c"
71 bind $win.pane_sash <ButtonRelease-1> "::utils::pane::Drop $win $c"
77 proc ::utils::pane::SetDrag {win bool} {
78 set ::utils::pane::_data($win,drag) $bool
81 proc ::utils::pane::SetRange {win min max} {
82 set ::utils::pane::_data($win,min) $min
83 set ::utils::pane::_data($win,max) $max
86 proc ::utils::pane::Enter {win} {
91 proc ::utils::pane::Leave {win} {
96 proc ::utils::pane::Grab {win} {
101 proc ::utils::pane::Drag {win y} {
103 set vertical $_data($win,vertical)
105 set realY [
expr {$y-[winfo rooty $win]}]
106 set Ymax [
winfo height $win]
108 set realY [
expr {$y-[winfo rootx $win]}]
109 set Ymax [
winfo width $win]
111 set frac [
expr {double($realY) / $Ymax}]
112 if {$frac < $_data($win,min)} {
set frac $_data($win,min)}
113 if {$frac > $_data($win,max)} {
set frac $_data($win,max)}
115 if {$_data($win,drag)} {
119 place $win.pane_sash -rely $frac
120 place $win.pane_grip -rely $frac
122 place $win.pane_sash -relx $frac
123 place $win.pane_grip -relx $frac
129 proc ::utils::pane::Drop {win y} {
136 proc ::utils::pane::Divide {win frac} {
137 if {$::utils::pane::_data($win,vertical)} {
138 place $win.pane_sash -rely $frac
139 place $win.pane_grip -rely $frac
140 place $win.$::utils::pane::_data($win,1) -relheight $frac
141 place $win.$::utils::pane::_data($win,2) -relheight [
expr {1.0 - $frac}]
143 place $win.pane_sash -relx $frac
144 place $win.pane_grip -relx $frac
145 place $win.$::utils::pane::_data($win,1) -relwidth $frac
146 place $win.$::utils::pane::_data($win,2) -relwidth [
expr {1.0 - $frac}]