source: tol/tolbase/lib/toltk/panedw.tcl @ 4c5e200

1941-docker-image-to-testdevel
Last change on this file since 4c5e200 was 6d7779d, checked in by Jorge Pérez <josp.jorge@…>, 18 years ago

initial import

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 12.2 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : panedw.tcl
3# PURPOSE : This file is part of Unifix BWidget Toolkit
4#/////////////////////////////////////////////////////////////////////////////
5
6namespace eval PanedWindow {
7    namespace eval Pane {
8        Widget::declare PanedWindow::Pane {
9            {-minsize Int 0 0 "%d >= 0"}
10            {-weight  Int 1 0 "%d >= 0"}
11        }
12    }
13
14    Widget::declare PanedWindow {
15        {-side       Enum       top 1 {top left bottom right}}
16        {-width      Int        10  1 "%d >=3"}
17        {-pad        Int        4   1 "%d >= 0"}
18        {-background TkResource ""  0 frame}
19        {-bg         Synonym    -background}
20    }
21
22    variable _panedw
23
24    proc ::PanedWindow { path args } { return [eval PanedWindow::create $path $args] }
25    proc use {} {}
26}
27
28
29
30# ------------------------------------------------------------------------------
31#  Command PanedWindow::create
32# ------------------------------------------------------------------------------
33proc PanedWindow::create { path args } {
34    variable _panedw
35
36    Widget::init PanedWindow $path $args
37
38    frame $path -background [Widget::cget $path -background] -class PanedWindow
39    set _panedw($path,nbpanes) 0
40
41    bind $path <Configure> "PanedWindow::_realize $path %w %h"
42    bind $path <Destroy>   "PanedWindow::_destroy $path"
43
44    rename $path ::$path:cmd
45    proc ::$path { cmd args } "return \[eval PanedWindow::\$cmd $path \$args\]"
46
47    return $path
48}
49
50
51# ------------------------------------------------------------------------------
52#  Command PanedWindow::configure
53# ------------------------------------------------------------------------------
54proc PanedWindow::configure { path args } {
55    variable _panedw
56
57    set res [Widget::configure $path $args]
58
59    if { [Widget::hasChanged $path -background bg] && $_panedw($path,nbpanes) > 0 } {
60        $path:cmd configure -background $bg
61        $path.f0 configure -background $bg
62        for {set i 1} {$i < $_panedw($path,nbpanes)} {incr i} {
63            set frame $path.sash$i
64            $frame configure -background $bg
65            $frame.sep configure -background $bg
66            $frame.but configure -background $bg
67            $path.f$i configure -background $bg
68            $path.f$i.frame configure -background $bg
69        }
70    }
71    return $res
72}
73
74
75# ------------------------------------------------------------------------------
76#  Command PanedWindow::cget
77# ------------------------------------------------------------------------------
78proc PanedWindow::cget { path option } {
79    return [Widget::cget $path $option]
80}
81
82
83# ------------------------------------------------------------------------------
84#  Command PanedWindow::add
85# ------------------------------------------------------------------------------
86proc PanedWindow::add { path args } {
87    variable _panedw
88
89    set num $_panedw($path,nbpanes)
90    Widget::init PanedWindow::Pane $path.f$num $args
91    set bg [Widget::getoption $path -background]
92
93    set wbut  [Widget::getoption $path -width]
94    set pad   [Widget::getoption $path -pad]
95    set width [expr {$wbut+2*$pad}]
96    set side  [Widget::getoption $path -side]
97    if { $num > 0 } {
98        set frame [frame $path.sash$num -relief flat -bd 0 \
99                -highlightthickness 0 -width $width -height $width -bg $bg]
100        set sep   [frame $frame.sep -bd 5 -relief raised \
101                -highlightthickness 0 -bg $bg]
102        set but   [frame $frame.but -bd 1 -relief raised \
103                -highlightthickness 0 -bg $bg -width $wbut -height $wbut]
104        set placeButton 1
105        set sepsize     2
106        if { $::tcl_platform(platform) != "windows" } {
107            # We want to use a separator similar to windows
108            # so we comment the next line and add the behaviour from
109            # windows
110            #set activator $but
111           
112            # this lines are added for TOL
113            set activator $sep
114            set sepsize 4
115            #$sep configure -bd 3
116            $sep configure -bd 1
117            set placeButton 0
118           
119        } else {
120            set activator $sep
121            set sepsize 4
122            #$sep configure -bd 3
123            $sep configure -bd 1
124            set placeButton 0
125        }
126        if { ![string compare $side "top"] || \
127                ![string compare $side "bottom"] } {
128            place $sep -relx 0.5 -y 0 -width $sepsize -relheight 1.0 -anchor n
129            if { $placeButton } {
130                if { ![string compare $side "top"] } {
131                    place $but -relx 0.5 -y [expr {6+$wbut/2}] -anchor c
132                } else {
133                    place $but -relx 0.5 -rely 1.0 -y [expr {-6-$wbut/2}] \
134                            -anchor c
135                }
136            }
137            $activator configure -cursor sb_h_double_arrow
138            grid $frame -column [expr {2*$num-1}] -row 0 -sticky ns
139            grid columnconfigure $path [expr {2*$num-1}] -weight 0
140        } else {
141            place $sep -x 0 -rely 0.5 -height $sepsize -relwidth 1.0 -anchor w
142            if { $placeButton } {
143                if { ![string compare $side "left"] } {
144                    place $but -rely 0.5 -x [expr {6+$wbut/2}] -anchor c
145                } else {
146                    place $but -rely 0.5 -relx 1.0 -x [expr {-6-$wbut/2}] \
147                            -anchor c
148                }
149            }
150            $activator configure -cursor sb_v_double_arrow
151            grid $frame -row [expr {2*$num-1}] -column 0 -sticky ew
152            grid rowconfigure $path [expr {2*$num-1}] -weight 0
153        }
154        bind $activator <ButtonPress-1> \
155                "PanedWindow::_beg_move_sash $path $num %X %Y"
156    } else {
157        if { ![string compare $side "top"] || \
158                ![string compare $side "bottom"] } {
159            grid rowconfigure $path 0 -weight 1
160        } else {
161            grid columnconfigure $path 0 -weight 1
162        }
163    }
164
165    set pane [frame $path.f$num -bd 0 -relief flat \
166            -highlightthickness 0 -bg $bg]
167    set user [frame $path.f$num.frame  -bd 0 -relief flat \
168            -highlightthickness 0 -bg $bg]
169    if { ![string compare $side "top"] || ![string compare $side "bottom"] } {
170        grid $pane -column [expr {2*$num}] -row 0 -sticky nsew
171        grid columnconfigure $path [expr {2*$num}] \
172            -weight  [Widget::getoption $path.f$num -weight]
173    } else {
174        grid $pane -row [expr {2*$num}] -column 0 -sticky nsew
175        grid rowconfigure $path [expr {2*$num}] \
176            -weight  [Widget::getoption $path.f$num -weight]
177    }
178    pack $user -fill both -expand yes
179    incr _panedw($path,nbpanes)
180
181    return $user
182}
183
184
185# ------------------------------------------------------------------------------
186#  Command PanedWindow::getframe
187# ------------------------------------------------------------------------------
188proc PanedWindow::getframe { path index } {
189    if { [winfo exists $path.f$index.frame] } {
190        return $path.f$index.frame
191    }
192}
193
194
195# ------------------------------------------------------------------------------
196#  Command PanedWindow::_destroy
197# ------------------------------------------------------------------------------
198proc PanedWindow::_destroy { path } {
199    variable _panedw
200
201    for {set i 0} {$i < $_panedw($path,nbpanes)} {incr i} {
202        Widget::destroy $path.f$i
203    }
204    unset _panedw($path,nbpanes)
205    Widget::destroy $path
206    # Esta linea ya no aparece en la version 1.7.1
207    #rename $path {}
208}
209   
210
211# ------------------------------------------------------------------------------
212#  Command PanedWindow::_beg_move_sash
213# ------------------------------------------------------------------------------
214proc PanedWindow::_beg_move_sash { path num x y } {
215    variable _panedw
216
217    set fprev $path.f[expr {$num-1}]
218    set fnext $path.f$num
219    set wsash [expr {[Widget::getoption $path -width] + 2*[Widget::getoption $path -pad]}]
220
221    $path.sash$num.but configure -relief sunken
222    set top  [toplevel $path.sash -borderwidth 1 -relief raised]
223
224    set minszg [Widget::getoption $fprev -minsize]
225    set minszd [Widget::getoption $fnext -minsize]
226    set side   [Widget::getoption $path -side]
227
228    if { ![string compare $side "top"] || ![string compare $side "bottom"] } {
229        $top configure -cursor sb_h_double_arrow
230        set h    [winfo height $path]
231        set yr   [winfo rooty $path.sash$num]
232        set xmin [expr {$wsash/2+[winfo rootx $fprev]+$minszg}]
233        set xmax [expr {-$wsash/2-1+[winfo rootx $fnext]+[winfo width $fnext]-$minszd}]
234        wm overrideredirect $top 1
235        wm geom $top "2x${h}+$x+$yr"
236
237        update idletasks
238        grab set $top
239        bind $top <ButtonRelease-1> "PanedWindow::_end_move_sash $path $top $num $xmin $xmax %X rootx width"
240        bind $top <Motion>          "PanedWindow::_move_sash $top $xmin $xmax %X +%%d+$yr"
241        _move_sash $top $xmin $xmax $x "+%d+$yr"
242    } else {
243        $top configure -cursor sb_v_double_arrow
244        set w    [winfo width $path]
245        set xr   [winfo rootx $path.sash$num]
246        set ymin [expr {$wsash/2+[winfo rooty $fprev]+$minszg}]
247        set ymax [expr {-$wsash/2-1+[winfo rooty $fnext]+[winfo height $fnext]-$minszd}]
248        wm overrideredirect $top 1
249        wm geom $top "${w}x2+$xr+$y"
250
251        update idletasks
252        grab set $top
253        bind $top <ButtonRelease-1> "PanedWindow::_end_move_sash $path $top $num $ymin $ymax %Y rooty height"
254        bind $top <Motion>          "PanedWindow::_move_sash $top $ymin $ymax %Y +$xr+%%d"
255        _move_sash $top $ymin $ymax $y "+$xr+%d"
256    }
257}
258
259
260# ------------------------------------------------------------------------------
261#  Command PanedWindow::_move_sash
262# ------------------------------------------------------------------------------
263proc PanedWindow::_move_sash { top min max v form } {
264
265    if { $v < $min } {
266        set v $min
267    } elseif { $v > $max } {
268        set v $max
269    }
270    wm geom $top [format $form $v]
271}
272
273
274# ------------------------------------------------------------------------------
275#  Command PanedWindow::_end_move_sash
276# ------------------------------------------------------------------------------
277proc PanedWindow::_end_move_sash { path top num min max v rootv size } {
278  #Tolcon_Trace "path: $path, top: $top, num: $num, min: $min, max: $max, v: $v, rootv: $rootv, size: $size"
279    variable _panedw
280
281    destroy $top
282    if { $v < $min } {
283        set v $min
284    } elseif { $v > $max } {
285        set v $max
286    }
287    set fprev $path.f[expr {$num-1}]
288    set fnext $path.f$num
289
290    $path.sash$num.but configure -relief raised
291
292    set wsash [expr {[Widget::getoption $path -width] + 2*[Widget::getoption $path -pad]}]
293    set dv    [expr {$v-[winfo $rootv $path.sash$num]-$wsash/2}]
294    set w1    [winfo $size $fprev]
295    set w2    [winfo $size $fnext]
296
297    for {set i 0} {$i < $_panedw($path,nbpanes)} {incr i} {
298        if { $i == $num-1} {
299            $fprev configure -$size [expr {[winfo $size $fprev]+$dv}]
300        } elseif { $i == $num } {
301            $fnext configure -$size [expr {[winfo $size $fnext]-$dv}]
302        } else {
303            $path.f$i configure -$size [winfo $size $path.f$i]
304        }
305    }
306}
307
308
309# ------------------------------------------------------------------------------
310#  Command PanedWindow::_realize
311# ------------------------------------------------------------------------------
312proc PanedWindow::_realize { path width height } {
313    variable _panedw
314
315    set x    0
316    set y    0
317    set hc   [winfo reqheight $path]
318    set hmax 0
319    for {set i 0} {$i < $_panedw($path,nbpanes)} {incr i} {
320        $path.f$i configure \
321            -width  [winfo reqwidth  $path.f$i.frame] \
322            -height [winfo reqheight $path.f$i.frame]
323        place $path.f$i.frame -x 0 -y 0 -relwidth 1 -relheight 1
324    }
325
326    bind $path <Configure> {}
327}
328
329proc PanedWindow::MoveSash {path num axis where} {
330  Tolcon_Trace "Llamada a MoveSash. path=$path, num=$num, axis=$axis, where=$where"
331  set fprev $path.f[expr {$num-1}]
332  set fnext $path.f$num
333  set wsash [expr {[Widget::getoption $path -width] + 2*[Widget::getoption $path -pad]}]
334
335  set minszg [Widget::getoption $fprev -minsize]
336  set minszd [Widget::getoption $fnext -minsize]
337
338  if {[string equal $axis "x"]} {
339    set min [expr {$wsash/2+[winfo rootx $fprev]+$minszg}]
340    set max [expr {-$wsash/2-1+[winfo rootx $fnext]+[winfo width $fnext]-$minszd}]
341    set rootv "rootx"
342    set size  "width"
343  } else  {
344    set min [expr {$wsash/2+[winfo rooty $fprev]+$minszg}]
345    set max [expr {-$wsash/2-1+[winfo rooty $fnext]+[winfo height $fnext]-$minszd}]
346    set rootv "rooty"
347    set size  "height"
348  }
349
350  switch -- $where {
351    max     { set pos $max }
352    min     { set pos $min}
353    default { set pos [expr ($min+$max)/2]}
354  }
355  PanedWindow::_end_move_sash $path "" $num $min $max $pos $rootv $size
356}
Note: See TracBrowser for help on using the repository browser.