diff options
-rw-r--r-- | doc/ttk_treeview.n | 26 | ||||
-rw-r--r-- | generic/ttk/ttkTreeview.c | 29 | ||||
-rw-r--r-- | library/ttk/treeview.tcl | 5 | ||||
-rw-r--r-- | tests/ttk/treeview.test | 88 |
4 files changed, 126 insertions, 22 deletions
diff --git a/doc/ttk_treeview.n b/doc/ttk_treeview.n index 5fd5e6d..125cc78 100644 --- a/doc/ttk_treeview.n +++ b/doc/ttk_treeview.n @@ -133,25 +133,29 @@ The column name. This is a read-only option. For example, [\fI$pathname \fBcolumn #\fIn \fB\-id\fR] returns the data column associated with display column #\fIn\fR. .TP -\fB\-anchor\fR +\fB\-anchor \fIanchor\fR Specifies how the text in this column should be aligned -with respect to the cell. One of +with respect to the cell. \fIAnchor\fR is one of \fBn\fR, \fBne\fR, \fBe\fR, \fBse\fR, \fBs\fR, \fBsw\fR, \fBw\fR, \fBnw\fR, or \fBcenter\fR. .TP -\fB\-minwidth\fR +\fB\-minwidth \fIminwidth\fR The minimum width of the column in pixels. The treeview widget will not make the column any smaller than \fB\-minwidth\fR when the widget is resized or the user drags a +column separator. Default is 20 pixels. +.TP +\fB\-stretch \fIboolean\fR +Specifies whether or not the column width should be adjusted +when the widget is resized or the user drags a column separator. +\fIBoolean\fR may have any of the forms accepted by \fBTcl_GetBoolean\fR. +By default columns are stretchable. +.TP +\fB\-width \fIwidth\fR +The width of the column in pixels. Default is 200 pixels. The specified +column width may be changed by Tk in order to honor \fB\-stretch\fR +and/or \fB\-minwidth\fR, or when the widget is resized or the user drags a column separator. -.TP -\fB\-stretch\fR -Specifies whether or not the column's width should be adjusted -when the widget is resized. -.TP -\fB\-width \fIw\fR -The width of the column in pixels. Default is something reasonable, -probably 200 or so. .PP Use \fIpathname column #0\fR to configure the tree column. .RE diff --git a/generic/ttk/ttkTreeview.c b/generic/ttk/ttkTreeview.c index 492961d..ccc5e2e 100644 --- a/generic/ttk/ttkTreeview.c +++ b/generic/ttk/ttkTreeview.c @@ -282,7 +282,7 @@ static Tk_OptionSpec ColumnOptionSpecs[] = { 0,0,0 }, {TK_OPTION_BOOLEAN, "-stretch", "stretch", "Stretch", "1", -1, Tk_Offset(TreeColumn,stretch), - 0,0,0 }, + 0,0,GEOMETRY_CHANGED }, {TK_OPTION_ANCHOR, "-anchor", "anchor", "Anchor", "w", Tk_Offset(TreeColumn,anchorObj), -1, /* <<NOTE-ANCHOR>> */ 0,0,0 }, @@ -1232,13 +1232,13 @@ static int ConfigureColumn( if (mask & GEOMETRY_CHANGED) { if (!Tk_IsMapped(tv->core.tkwin)) { TtkResizeWidget(&tv->core); - } - RecomputeSlack(tv); + } else { + RecomputeSlack(tv); + ResizeColumns(tv, TreeWidth(tv)); + } } TtkRedisplayWidget(&tv->core); - /* ASSERT: SLACKINVARIANT */ - Tk_FreeSavedOptions(&savedOptions); return TCL_OK; @@ -1615,13 +1615,10 @@ static void TreeviewDoLayout(void *clientData) Treeview *tv = clientData; int visibleRows; - /* ASSERT: SLACKINVARIANT */ - Ttk_PlaceLayout(tv->core.layout,tv->core.state,Ttk_WinBox(tv->core.tkwin)); tv->tree.treeArea = Ttk_ClientRegion(tv->core.layout, "treearea"); ResizeColumns(tv, tv->tree.treeArea.width); - /* ASSERT: SLACKINVARIANT */ TtkScrolled(tv->tree.xscrollHandle, tv->tree.xscroll.first, @@ -2892,7 +2889,6 @@ static int TreeviewDragCommand( int right = left + c->width; if (c == column) { DragColumn(tv, i, newx - right); - /* ASSERT: SLACKINVARIANT */ TtkRedisplayWidget(&tv->core); return TCL_OK; } @@ -2905,6 +2901,20 @@ static int TreeviewDragCommand( return TCL_ERROR; } +static int TreeviewDropCommand( + void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) +{ + Treeview *tv = recordPtr; + + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "drop"); + return TCL_ERROR; + } + ResizeColumns(tv, TreeWidth(tv)); + TtkRedisplayWidget(&tv->core); + return TCL_OK; +} + /*------------------------------------------------------------------------ * +++ Widget commands -- focus and selection */ @@ -3254,6 +3264,7 @@ static const Ttk_Ensemble TreeviewCommands[] = { { "delete", TreeviewDeleteCommand,0 }, { "detach", TreeviewDetachCommand,0 }, { "drag", TreeviewDragCommand,0 }, + { "drop", TreeviewDropCommand,0 }, { "exists", TreeviewExistsCommand,0 }, { "focus", TreeviewFocusCommand,0 }, { "heading", TreeviewHeadingCommand,0 }, diff --git a/library/ttk/treeview.tcl b/library/ttk/treeview.tcl index 6a6f5d4..4158739 100644 --- a/library/ttk/treeview.tcl +++ b/library/ttk/treeview.tcl @@ -120,7 +120,8 @@ proc ttk::treeview::ActivateHeading {w heading} { variable State if {$w != $State(activeWidget) || $heading != $State(activeHeading)} { - if {[winfo exists $State(activeWidget)] && $State(activeHeading) != {}} { + if {[winfo exists $State(activeWidget)] && $State(activeHeading) != {} + && $State(activeHeading) in [$State(activeWidget) cget -displaycolumns]} { $State(activeWidget) heading $State(activeHeading) state !active } if {$heading != {}} { @@ -205,7 +206,7 @@ proc ttk::treeview::resize.drag {w x} { } proc ttk::treeview::resize.release {w x} { - # no-op + $w drop } ### Heading activation. diff --git a/tests/ttk/treeview.test b/tests/ttk/treeview.test index 4e92601..c9dcf52 100644 --- a/tests/ttk/treeview.test +++ b/tests/ttk/treeview.test @@ -692,4 +692,92 @@ test treeview-368fa4561e "indicators cannot be clicked on leafs" -setup { destroy .tv } -result {0 0 0} +test treeview-ce470f20fd-1 "dragging further than the right edge of the treeview is allowed" -setup { + pack [ttk::treeview .tv] + .tv heading #0 -text "Drag my right edge -->" + update +} -body { + set res [.tv column #0 -width] + .tv drag #0 400 + lappend res [expr {[.tv column #0 -width] > $res}] +} -cleanup { + destroy .tv +} -result {200 1} + +proc nostretch {tv} { + foreach col [$tv cget -columns] { + $tv column $col -stretch 0 + } + $tv column #0 -stretch 0 + update idletasks ; # redisplay $tv +} + +test treeview-ce470f20fd-2 "changing -stretch resizes columns" -setup { + pack [ttk::treeview .tv -columns {bar colA colB colC foo}] + foreach col [.tv cget -columns] { + .tv heading $col -text $col + } + nostretch .tv + .tv column colA -width 50 ; .tv column colB -width 50 ; # slack created + update idletasks ; # redisplay treeview +} -body { + # when no column is stretchable and one of them becomes stretchable + # the stretchable column takes the slack and the widget is redisplayed + # automatically at idle time + set res [.tv column colA -width] + .tv column colA -stretch 1 + update idletasks ; # no slack anymore, widget redisplayed + lappend res [expr {[.tv column colA -width] > $res}] +} -cleanup { + destroy .tv +} -result {50 1} + +test treeview-ce470f20fd-3 "changing -stretch resizes columns" -setup { + pack [ttk::treeview .tv -columns {bar colA colB colC foo}] + foreach col [.tv cget -columns] { + .tv heading $col -text $col + } + .tv configure -displaycolumns {colB colA colC} + nostretch .tv + .tv column colA -width 50 ; .tv column colB -width 50 ; # slack created + update idletasks ; # redisplay treeview +} -body { + # only some columns are displayed (and in a different order than declared + # in -columns), a displayed column becomes stretchable --> the stretchable + # column expands + set res [.tv column colA -width] + .tv column colA -stretch 1 + update idletasks ; # no slack anymore, widget redisplayed + lappend res [expr {[.tv column colA -width] > $res}] +} -cleanup { + destroy .tv +} -result {50 1} + +test treeview-ce470f20fd-4 "changing -stretch resizes columns" -setup { + pack [ttk::treeview .tv -columns {bar colA colB colC foo}] + foreach col [.tv cget -columns] { + .tv heading $col -text $col + } + .tv configure -displaycolumns {colB colA colC} + nostretch .tv + .tv column colA -width 50 ; .tv column bar -width 60 ; # slack created + update idletasks ; # redisplay treeview +} -body { + # only some columns are displayed (and in a different order than declared + # in -columns), a non-displayed column becomes stretchable --> nothing + # happens + set origTreeWidth [winfo width .tv] + set res [list [.tv column bar -width] [.tv column colA -width]] + .tv column bar -stretch 1 + update idletasks ; # no change, widget redisplayed + lappend res [.tv column bar -width] [.tv column colA -width] + # this column becomes visible --> widget resizes + .tv configure -displaycolumns {bar colC colA colB} + update idletasks ; # no slack anymore because the widget resizes (shrinks) + lappend res [.tv column bar -width] [.tv column colA -width] \ + [expr {[winfo width .tv] < $origTreeWidth}] +} -cleanup { + destroy .tv +} -result {60 50 60 50 60 50 1} + tcltest::cleanupTests |