Tk Library Source Code

Artifact [b7ebf6ed8e]
Login

Artifact b7ebf6ed8e348676d27746cf5332d33d998cc2c4:

Attachment "scrollf.patch" to ticket [2807227fff] added by danckaert 2009-06-16 22:30:04.
Index: scrollframe.tcl
===================================================================
RCS file: /target/staff/koen/.cvsroot/bwidget/scrollframe.tcl,v
retrieving revision 1.1.1.2
diff -b -u -r1.1.1.2 scrollframe.tcl
--- scrollframe.tcl	9 Nov 2006 11:34:59 -0000	1.1.1.2
+++ scrollframe.tcl	16 Jun 2009 15:15:40 -0000
@@ -68,8 +68,13 @@
         -width  [Widget::cget $path -areawidth] \
         -height [Widget::cget $path -areaheight]

-    bind $frame <Configure> \
-	    [list ScrollableFrame::_frameConfigure $canvas $frame %w %h]
+    # KD 2009/03/31: add <unmap> binding: <configure> is not called when frame
+    # becomes so small that it suddenly falls outside of currently visible area.
+    # KD 2009/04/17: but now we need to add a <map> binding too
+    bind $frame <Map>       [list ScrollableFrame::_frameConfigure $path 0]
+    bind $frame <Unmap>     [list ScrollableFrame::_frameConfigure $path 1]
+    bind $frame <Configure> [list ScrollableFrame::_frameConfigure $path 0]
+
     bindtags $path [list $path BwScrollableFrame [winfo toplevel $path] all]

     return [Widget::create ScrollableFrame $path]
@@ -207,20 +212,26 @@
     if { [Widget::getoption $path -constrainedheight] } {
         $path:cmd itemconfigure win -height [winfo height $path]
     }
+    # KD 2005/06/15: scollregion must also be reset when canvas size changes!
+    _frameConfigure $path 0
 }


 # ----------------------------------------------------------------------------
 #  Command ScrollableFrame::_frameConfigure
 # ----------------------------------------------------------------------------
-proc ScrollableFrame::_frameConfigure {canvas frame width height} {
+proc ScrollableFrame::_max {a b} {return [expr {$a <= $b ? $b : $a}]}
+proc ScrollableFrame::_frameConfigure {path unmap} {
     # This ensures that we don't get funny scrollability in the frame
-    # when it is smaller than the canvas space
-    if {[winfo height $frame] < [winfo height $canvas]} {
-	set height [winfo height $canvas]
-    }
-    if {[winfo width $frame] < [winfo width $canvas]} {
-	set width [winfo width $canvas]
-    }
-    $canvas:cmd configure -scrollregion [list 0 0 $width $height]
+    # when it is smaller than the canvas space.
+    # KD 2005/06/15: use [winfo] to get height & width of frame
+
+    # [winfo] doesn't work for unmapped frame
+    set frameh [expr {$unmap ? 0 : [winfo height $path.frame]}]
+    set framew [expr {$unmap ? 0 : [winfo width  $path.frame]}]
+
+    set h [_max $frameh [winfo height $path]]
+    set w [_max $framew [winfo width  $path]]
+
+    $path:cmd configure -scrollregion [list 0 0 $w $h]
 }