1# This file is a Tcl script to test out the "listbox" command 2# of Tk. It is organized in the standard fashion for Tcl tests. 3# 4# Copyright (c) 1993-1994 The Regents of the University of California. 5# Copyright (c) 1994-1997 Sun Microsystems, Inc. 6# Copyright (c) 1998-1999 by Scriptics Corporation. 7# All rights reserved. 8# 9# RCS: @(#) $Id: listbox.test,v 1.21.2.2 2006/05/29 21:52:47 hobbs Exp $ 10 11package require tcltest 2.1 12namespace import -force tcltest::configure 13namespace import -force tcltest::testsDirectory 14configure -testdir [file join [pwd] [file dirname [info script]]] 15configure -loadfile [file join [testsDirectory] constraints.tcl] 16tcltest::loadTestedCommands 17 18set fixed {Courier -12} 19 20proc record args { 21 global log 22 lappend log $args 23} 24 25proc getsize w { 26 regexp {(^[^+-]*)} [wm geometry $w] foo x 27 return $x 28} 29 30proc resetGridInfo {} { 31 # Some window managers, such as mwm, don't reset gridding information 32 # unless the window is withdrawn and re-mapped. If this procedure 33 # isn't invoked, the window manager will stay in gridded mode, which 34 # can cause all sorts of problems. The "wm positionfrom" command is 35 # needed so that the window manager doesn't ask the user to 36 # manually position the window when it is re-mapped. 37 38 wm withdraw . 39 wm positionfrom . user 40 wm deiconify . 41} 42 43# Procedure that creates a second listbox for checking things related 44# to partially visible lines. 45 46proc mkPartial {{w .partial}} { 47 catch {destroy $w} 48 toplevel $w 49 wm geometry $w +0+0 50 listbox $w.l -width 30 -height 5 51 pack $w.l -expand 1 -fill both 52 $w.l insert end one two three four five six seven eight nine ten \ 53 eleven twelve thirteen fourteen fifteen 54 update 55 scan [wm geometry $w] "%dx%d" width height 56 wm geometry $w ${width}x[expr $height-3] 57 update 58} 59 60# Create entries in the option database to be sure that geometry options 61# like border width have predictable values. 62 63option add *Listbox.borderWidth 2 64option add *Listbox.highlightThickness 2 65option add *Listbox.font {Helvetica -12 bold} 66 67listbox .l 68pack .l 69update 70resetGridInfo 71set i 1 72 73foreach test { 74 {-activestyle under underline foo {bad activestyle "foo": must be dotbox, none, or underline}} 75 {-background #ff0000 #ff0000 non-existent 76 {unknown color name "non-existent"}} 77 {-bd 4 4 badValue {bad screen distance "badValue"}} 78 {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}} 79 {-borderwidth 1.3 1 badValue {bad screen distance "badValue"}} 80 {-cursor arrow arrow badValue {bad cursor spec "badValue"}} 81 {-disabledforeground #110022 #110022 bogus {unknown color name "bogus"}} 82 {-exportselection yes 1 xyzzy {expected boolean value but got "xyzzy"}} 83 {-fg #110022 #110022 bogus {unknown color name "bogus"}} 84 {-font {Helvetica 12} {Helvetica 12} {} {font "" doesn't exist}} 85 {-foreground #110022 #110022 bogus {unknown color name "bogus"}} 86 {-height 30 30 20p {expected integer but got "20p"}} 87 {-highlightbackground #112233 #112233 ugly {unknown color name "ugly"}} 88 {-highlightcolor #123456 #123456 bogus {unknown color name "bogus"}} 89 {-highlightthickness 6 6 bogus {bad screen distance "bogus"}} 90 {-highlightthickness -2 0 {} {}} 91 {-relief groove groove 1.5 {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}} 92 {-selectbackground #110022 #110022 bogus {unknown color name "bogus"}} 93 {-selectborderwidth 1.3 1 badValue {bad screen distance "badValue"}} 94 {-selectforeground #654321 #654321 bogus {unknown color name "bogus"}} 95 {-selectmode string string {} {}} 96 {-setgrid false 0 lousy {expected boolean value but got "lousy"}} 97 {-state disabled disabled foo {bad state "foo": must be disabled or normal}} 98 {-takefocus "any string" "any string" {} {}} 99 {-width 45 45 3p {expected integer but got "3p"}} 100 {-xscrollcommand {Some command} {Some command} {} {}} 101 {-yscrollcommand {Another command} {Another command} {} {}} 102 {-listvar testVariable testVariable {} {}} 103} { 104 set name [lindex $test 0] 105 test listbox-1.$i {configuration options} { 106 .l configure $name [lindex $test 1] 107 list [lindex [.l configure $name] 4] [.l cget $name] 108 } [list [lindex $test 2] [lindex $test 2]] 109 incr i 110 if {[lindex $test 3] != ""} { 111 test listbox-1.$i {configuration options} { 112 list [catch {.l configure $name [lindex $test 3]} msg] $msg 113 } [list 1 [lindex $test 4]] 114 } 115 .l configure $name [lindex [.l configure $name] 3] 116 incr i 117} 118 119test listbox-2.1 {Tk_ListboxCmd procedure} { 120 list [catch {listbox} msg] $msg 121} {1 {wrong # args: should be "listbox pathName ?options?"}} 122test listbox-2.2 {Tk_ListboxCmd procedure} { 123 list [catch {listbox gorp} msg] $msg 124} {1 {bad window path name "gorp"}} 125test listbox-2.3 {Tk_ListboxCmd procedure} { 126 catch {destroy .l} 127 listbox .l 128 list [winfo exists .l] [winfo class .l] [info commands .l] 129} {1 Listbox .l} 130test listbox-2.4 {Tk_ListboxCmd procedure} { 131 catch {destroy .l} 132 list [catch {listbox .l -gorp foo} msg] $msg [winfo exists .l] \ 133 [info commands .l] 134} {1 {unknown option "-gorp"} 0 {}} 135test listbox-2.5 {Tk_ListboxCmd procedure} { 136 catch {destroy .l} 137 listbox .l 138} {.l} 139 140catch {destroy .l} 141listbox .l -width 20 -height 5 -bd 4 -highlightthickness 1 -selectborderwidth 2 142pack .l 143.l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11 el12 el13 el14 \ 144 el15 el16 el17 145update 146test listbox-3.1 {ListboxWidgetCmd procedure} { 147 list [catch .l msg] $msg 148} {1 {wrong # args: should be ".l option ?arg arg ...?"}} 149test listbox-3.2 {ListboxWidgetCmd procedure, "activate" option} { 150 list [catch {.l activate} msg] $msg 151} {1 {wrong # args: should be ".l activate index"}} 152test listbox-3.3 {ListboxWidgetCmd procedure, "activate" option} { 153 list [catch {.l activate a b} msg] $msg 154} {1 {wrong # args: should be ".l activate index"}} 155test listbox-3.4 {ListboxWidgetCmd procedure, "activate" option} { 156 list [catch {.l activate fooey} msg] $msg 157} {1 {bad listbox index "fooey": must be active, anchor, end, @x,y, or a number}} 158test listbox-3.5 {ListboxWidgetCmd procedure, "activate" option} { 159 .l activate 3 160 .l index active 161} 3 162test listbox-3.6 {ListboxWidgetCmd procedure, "activate" option} { 163 .l activate -1 164 .l index active 165} {0} 166test listbox-3.7 {ListboxWidgetCmd procedure, "activate" option} { 167 .l activate 30 168 .l index active 169} {17} 170test listbox-3.8 {ListboxWidgetCmd procedure, "activate" option} { 171 .l activate end 172 .l index active 173} {17} 174test listbox-3.9 {ListboxWidgetCmd procedure, "bbox" option} { 175 list [catch {.l bbox} msg] $msg 176} {1 {wrong # args: should be ".l bbox index"}} 177test listbox-3.10 {ListboxWidgetCmd procedure, "bbox" option} { 178 list [catch {.l bbox a b} msg] $msg 179} {1 {wrong # args: should be ".l bbox index"}} 180test listbox-3.11 {ListboxWidgetCmd procedure, "bbox" option} { 181 list [catch {.l bbox fooey} msg] $msg 182} {1 {bad listbox index "fooey": must be active, anchor, end, @x,y, or a number}} 183test listbox-3.12 {ListboxWidgetCmd procedure, "bbox" option} { 184 .l yview 3 185 update 186 list [.l bbox 2] [.l bbox 8] 187} {{} {}} 188test listbox-3.13 {ListboxWidgetCmd procedure, "bbox" option} { 189 # Used to generate a core dump before a bug was fixed (the last 190 # element would be on-screen if it existed, but it doesn't exist). 191 192 listbox .l2 193 pack .l2 -side top 194 tkwait visibility .l2 195 set x [.l2 bbox 0] 196 destroy .l2 197 set x 198} {} 199test listbox-3.14 {ListboxWidgetCmd procedure, "bbox" option} {fonts} { 200 .l yview 3 201 update 202 list [.l bbox 3] [.l bbox 4] 203} {{7 7 17 14} {7 26 17 14}} 204test listbox-3.15 {ListboxWidgetCmd procedure, "bbox" option} {fonts} { 205 .l yview 0 206 update 207 list [.l bbox -1] [.l bbox 0] 208} {{} {7 7 17 14}} 209test listbox-3.16 {ListboxWidgetCmd procedure, "bbox" option} {fonts} { 210 .l yview end 211 update 212 list [.l bbox 17] [.l bbox end] [.l bbox 18] 213} {{7 83 24 14} {7 83 24 14} {}} 214test listbox-3.17 {ListboxWidgetCmd procedure, "bbox" option} {fonts} { 215 catch {destroy .t} 216 toplevel .t 217 wm geom .t +0+0 218 listbox .t.l -width 10 -height 5 219 .t.l insert 0 "Short" "Somewhat longer" "Really, quite a whole lot longer than can possibly fit on the screen" "Short" 220 pack .t.l 221 update 222 .t.l xview moveto .2 223 .t.l bbox 2 224} {-72 39 393 14} 225test listbox-3.18 {ListboxWidgetCmd procedure, "bbox" option, partial last line} {fonts} { 226 mkPartial 227 list [.partial.l bbox 3] [.partial.l bbox 4] 228} {{5 56 24 14} {5 73 23 14}} 229test listbox-3.19 {ListboxWidgetCmd procedure, "cget" option} { 230 list [catch {.l cget} msg] $msg 231} {1 {wrong # args: should be ".l cget option"}} 232test listbox-3.20 {ListboxWidgetCmd procedure, "cget" option} { 233 list [catch {.l cget a b} msg] $msg 234} {1 {wrong # args: should be ".l cget option"}} 235test listbox-3.21 {ListboxWidgetCmd procedure, "cget" option} { 236 list [catch {.l cget -gorp} msg] $msg 237} {1 {unknown option "-gorp"}} 238test listbox-3.22 {ListboxWidgetCmd procedure, "cget" option} { 239 .l cget -setgrid 240} {0} 241test listbox-3.23 {ListboxWidgetCmd procedure, "configure" option} { 242 llength [.l configure] 243} {27} 244test listbox-3.24 {ListboxWidgetCmd procedure, "configure" option} { 245 list [catch {.l configure -gorp} msg] $msg 246} {1 {unknown option "-gorp"}} 247test listbox-3.25 {ListboxWidgetCmd procedure, "configure" option} { 248 .l configure -setgrid 249} {-setgrid setGrid SetGrid 0 0} 250test listbox-3.26 {ListboxWidgetCmd procedure, "configure" option} { 251 list [catch {.l configure -gorp is_messy} msg] $msg 252} {1 {unknown option "-gorp"}} 253test listbox-3.27 {ListboxWidgetCmd procedure, "configure" option} { 254 set oldbd [.l cget -bd] 255 set oldht [.l cget -highlightthickness] 256 .l configure -bd 3 -highlightthickness 0 257 set x "[.l cget -bd] [.l cget -highlightthickness]" 258 .l configure -bd $oldbd -highlightthickness $oldht 259 set x 260} {3 0} 261test listbox-3.28 {ListboxWidgetCmd procedure, "curselection" option} { 262 list [catch {.l curselection a} msg] $msg 263} {1 {wrong # args: should be ".l curselection"}} 264test listbox-3.29 {ListboxWidgetCmd procedure, "curselection" option} { 265 .l selection clear 0 end 266 .l selection set 3 6 267 .l selection set 9 268 .l curselection 269} {3 4 5 6 9} 270test listbox-3.30 {ListboxWidgetCmd procedure, "delete" option} { 271 list [catch {.l delete} msg] $msg 272} {1 {wrong # args: should be ".l delete firstIndex ?lastIndex?"}} 273test listbox-3.31 {ListboxWidgetCmd procedure, "delete" option} { 274 list [catch {.l delete a b c} msg] $msg 275} {1 {wrong # args: should be ".l delete firstIndex ?lastIndex?"}} 276test listbox-3.32 {ListboxWidgetCmd procedure, "delete" option} { 277 list [catch {.l delete badIndex} msg] $msg 278} {1 {bad listbox index "badIndex": must be active, anchor, end, @x,y, or a number}} 279test listbox-3.33 {ListboxWidgetCmd procedure, "delete" option} { 280 list [catch {.l delete 2 123ab} msg] $msg 281} {1 {bad listbox index "123ab": must be active, anchor, end, @x,y, or a number}} 282test listbox-3.34 {ListboxWidgetCmd procedure, "delete" option} { 283 catch {destroy .l2} 284 listbox .l2 285 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7 286 .l2 delete 3 287 list [.l2 get 2] [.l2 get 3] [.l2 index end] 288} {el2 el4 7} 289test listbox-3.35 {ListboxWidgetCmd procedure, "delete" option} { 290 catch {destroy .l2} 291 listbox .l2 292 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7 293 .l2 delete 2 4 294 list [.l2 get 1] [.l2 get 2] [.l2 index end] 295} {el1 el5 5} 296test listbox-3.36 {ListboxWidgetCmd procedure, "delete" option} { 297 catch {destroy .l2} 298 listbox .l2 299 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7 300 .l2 delete -3 2 301 .l2 get 0 end 302} {el3 el4 el5 el6 el7} 303test listbox-3.37 {ListboxWidgetCmd procedure, "delete" option} { 304 catch {destroy .l2} 305 listbox .l2 306 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7 307 .l2 delete -3 -1 308 .l2 get 0 end 309} {el0 el1 el2 el3 el4 el5 el6 el7} 310test listbox-3.38 {ListboxWidgetCmd procedure, "delete" option} { 311 catch {destroy .l2} 312 listbox .l2 313 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7 314 .l2 delete 2 end 315 .l2 get 0 end 316} {el0 el1} 317test listbox-3.39 {ListboxWidgetCmd procedure, "delete" option} { 318 catch {destroy .l2} 319 listbox .l2 320 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7 321 .l2 delete 5 20 322 .l2 get 0 end 323} {el0 el1 el2 el3 el4} 324test listbox-3.40 {ListboxWidgetCmd procedure, "delete" option} { 325 catch {destroy .l2} 326 listbox .l2 327 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7 328 .l2 delete end 20 329 .l2 get 0 end 330} {el0 el1 el2 el3 el4 el5 el6} 331test listbox-3.41 {ListboxWidgetCmd procedure, "delete" option} { 332 catch {destroy .l2} 333 listbox .l2 334 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7 335 .l2 delete 8 20 336 .l2 get 0 end 337} {el0 el1 el2 el3 el4 el5 el6 el7} 338test listbox-3.42 {ListboxWidgetCmd procedure, "get" option} { 339 list [catch {.l get} msg] $msg 340} {1 {wrong # args: should be ".l get firstIndex ?lastIndex?"}} 341test listbox-3.43 {ListboxWidgetCmd procedure, "get" option} { 342 list [catch {.l get a b c} msg] $msg 343} {1 {wrong # args: should be ".l get firstIndex ?lastIndex?"}} 344test listbox-3.44 {ListboxWidgetCmd procedure, "get" option} { 345 list [catch {.l get 2.4} msg] $msg 346} {1 {bad listbox index "2.4": must be active, anchor, end, @x,y, or a number}} 347test listbox-3.45 {ListboxWidgetCmd procedure, "get" option} { 348 list [catch {.l get end bogus} msg] $msg 349} {1 {bad listbox index "bogus": must be active, anchor, end, @x,y, or a number}} 350test listbox-3.46 {ListboxWidgetCmd procedure, "get" option} { 351 catch {destroy .l2} 352 listbox .l2 353 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7 354 list [.l2 get 0] [.l2 get 3] [.l2 get end] 355} {el0 el3 el7} 356test listbox-3.47 {ListboxWidgetCmd procedure, "get" option} { 357 catch {destroy .l2} 358 listbox .l2 359 list [.l2 get 0] [.l2 get end] 360} {{} {}} 361test listbox-3.48 {ListboxWidgetCmd procedure, "get" option} { 362 catch {destroy .l2} 363 listbox .l2 364 .l2 insert 0 el0 el1 el2 "two words" el4 el5 el6 el7 365 .l2 get 3 end 366} {{two words} el4 el5 el6 el7} 367test listbox-3.49 {ListboxWidgetCmd procedure, "get" option} { 368 .l get -1 369} {} 370test listbox-3.50 {ListboxWidgetCmd procedure, "get" option} { 371 .l get -2 -1 372} {} 373test listbox-3.51 {ListboxWidgetCmd procedure, "get" option} { 374 .l get -2 3 375} {el0 el1 el2 el3} 376test listbox-3.52 {ListboxWidgetCmd procedure, "get" option} { 377 .l get 12 end 378} {el12 el13 el14 el15 el16 el17} 379test listbox-3.53 {ListboxWidgetCmd procedure, "get" option} { 380 .l get 12 20 381} {el12 el13 el14 el15 el16 el17} 382test listbox-3.54 {ListboxWidgetCmd procedure, "get" option} { 383 .l get end 384} {el17} 385test listbox-3.55 {ListboxWidgetCmd procedure, "get" option} { 386 .l get 30 387} {} 388test listbox-3.56 {ListboxWidgetCmd procedure, "get" option} { 389 .l get 30 35 390} {} 391test listbox-3.57 {ListboxWidgetCmd procedure, "index" option} { 392 list [catch {.l index} msg] $msg 393} {1 {wrong # args: should be ".l index index"}} 394test listbox-3.58 {ListboxWidgetCmd procedure, "index" option} { 395 list [catch {.l index a b} msg] $msg 396} {1 {wrong # args: should be ".l index index"}} 397test listbox-3.59 {ListboxWidgetCmd procedure, "index" option} { 398 list [catch {.l index @} msg] $msg 399} {1 {bad listbox index "@": must be active, anchor, end, @x,y, or a number}} 400test listbox-3.60 {ListboxWidgetCmd procedure, "index" option} { 401 .l index 2 402} 2 403test listbox-3.61 {ListboxWidgetCmd procedure, "index" option} { 404 .l index -1 405} -1 406test listbox-3.62 {ListboxWidgetCmd procedure, "index" option} { 407 .l index end 408} 18 409test listbox-3.63 {ListboxWidgetCmd procedure, "index" option} { 410 .l index 34 411} 34 412test listbox-3.64 {ListboxWidgetCmd procedure, "insert" option} { 413 list [catch {.l insert} msg] $msg 414} {1 {wrong # args: should be ".l insert index ?element element ...?"}} 415test listbox-3.65 {ListboxWidgetCmd procedure, "insert" option} { 416 list [catch {.l insert badIndex} msg] $msg 417} {1 {bad listbox index "badIndex": must be active, anchor, end, @x,y, or a number}} 418test listbox-3.66 {ListboxWidgetCmd procedure, "insert" option} { 419 catch {destroy .l2} 420 listbox .l2 421 .l2 insert end a b c d e 422 .l2 insert 3 x y z 423 .l2 get 0 end 424} {a b c x y z d e} 425test listbox-3.67 {ListboxWidgetCmd procedure, "insert" option} { 426 catch {destroy .l2} 427 listbox .l2 428 .l2 insert end a b c 429 .l2 insert -1 x 430 .l2 get 0 end 431} {x a b c} 432test listbox-3.68 {ListboxWidgetCmd procedure, "insert" option} { 433 catch {destroy .l2} 434 listbox .l2 435 .l2 insert end a b c 436 .l2 insert end x 437 .l2 get 0 end 438} {a b c x} 439test listbox-3.69 {ListboxWidgetCmd procedure, "insert" option} { 440 catch {destroy .l2} 441 listbox .l2 442 .l2 insert end a b c 443 .l2 insert 43 x 444 .l2 get 0 end 445} {a b c x} 446test listbox-3.70 {ListboxWidgetCmd procedure, "nearest" option} { 447 list [catch {.l nearest} msg] $msg 448} {1 {wrong # args: should be ".l nearest y"}} 449test listbox-3.71 {ListboxWidgetCmd procedure, "nearest" option} { 450 list [catch {.l nearest a b} msg] $msg 451} {1 {wrong # args: should be ".l nearest y"}} 452test listbox-3.72 {ListboxWidgetCmd procedure, "nearest" option} { 453 list [catch {.l nearest 20p} msg] $msg 454} {1 {expected integer but got "20p"}} 455test listbox-3.73 {ListboxWidgetCmd procedure, "nearest" option} { 456 .l yview 3 457 .l nearest 1000 458} {7} 459test listbox-3.74 {ListboxWidgetCmd procedure, "scan" option} { 460 list [catch {.l scan a b} msg] $msg 461} {1 {wrong # args: should be ".l scan mark|dragto x y"}} 462test listbox-3.75 {ListboxWidgetCmd procedure, "scan" option} { 463 list [catch {.l scan a b c d} msg] $msg 464} {1 {wrong # args: should be ".l scan mark|dragto x y"}} 465test listbox-3.76 {ListboxWidgetCmd procedure, "scan" option} { 466 list [catch {.l scan foo bogus 2} msg] $msg 467} {1 {expected integer but got "bogus"}} 468test listbox-3.77 {ListboxWidgetCmd procedure, "scan" option} { 469 list [catch {.l scan foo 2 2.3} msg] $msg 470} {1 {expected integer but got "2.3"}} 471test listbox-3.78 {ListboxWidgetCmd procedure, "scan" option} {fonts} { 472 catch {destroy .t} 473 toplevel .t 474 wm geom .t +0+0 475 listbox .t.l -width 10 -height 5 476 .t.l insert 0 "Short" "Somewhat longer" "Really, quite a whole lot longer than can possibly fit on the screen" "Short" a b c d e f g h i j 477 pack .t.l 478 update 479 .t.l scan mark 100 140 480 .t.l scan dragto 90 137 481 update 482 list [.t.l xview] [.t.l yview] 483} {{0.249364 0.427481} {0.0714286 0.428571}} 484test listbox-3.79 {ListboxWidgetCmd procedure, "scan" option} { 485 list [catch {.l scan foo 2 4} msg] $msg 486} {1 {bad option "foo": must be mark or dragto}} 487test listbox-3.80 {ListboxWidgetCmd procedure, "see" option} { 488 list [catch {.l see} msg] $msg 489} {1 {wrong # args: should be ".l see index"}} 490test listbox-3.81 {ListboxWidgetCmd procedure, "see" option} { 491 list [catch {.l see a b} msg] $msg 492} {1 {wrong # args: should be ".l see index"}} 493test listbox-3.82 {ListboxWidgetCmd procedure, "see" option} { 494 list [catch {.l see gorp} msg] $msg 495} {1 {bad listbox index "gorp": must be active, anchor, end, @x,y, or a number}} 496test listbox-3.83 {ListboxWidgetCmd procedure, "see" option} { 497 .l yview 7 498 .l see 7 499 .l index @0,0 500} {7} 501test listbox-3.84 {ListboxWidgetCmd procedure, "see" option} { 502 .l yview 7 503 .l see 11 504 .l index @0,0 505} {7} 506test listbox-3.85 {ListboxWidgetCmd procedure, "see" option} { 507 .l yview 7 508 .l see 6 509 .l index @0,0 510} {6} 511test listbox-3.86 {ListboxWidgetCmd procedure, "see" option} { 512 .l yview 7 513 .l see 5 514 .l index @0,0 515} {3} 516test listbox-3.87 {ListboxWidgetCmd procedure, "see" option} { 517 .l yview 7 518 .l see 12 519 .l index @0,0 520} {8} 521test listbox-3.88 {ListboxWidgetCmd procedure, "see" option} { 522 .l yview 7 523 .l see 13 524 .l index @0,0 525} {11} 526test listbox-3.89 {ListboxWidgetCmd procedure, "see" option} { 527 .l yview 7 528 .l see -1 529 .l index @0,0 530} {0} 531test listbox-3.90 {ListboxWidgetCmd procedure, "see" option} { 532 .l yview 7 533 .l see end 534 .l index @0,0 535} {13} 536test listbox-3.91 {ListboxWidgetCmd procedure, "see" option} { 537 .l yview 7 538 .l see 322 539 .l index @0,0 540} {13} 541test listbox-3.92 {ListboxWidgetCmd procedure, "see" option, partial last line} { 542 mkPartial 543 .partial.l see 4 544 .partial.l index @0,0 545} {1} 546test listbox-3.93 {ListboxWidgetCmd procedure, "selection" option} { 547 list [catch {.l select a} msg] $msg 548} {1 {wrong # args: should be ".l selection option index ?index?"}} 549test listbox-3.94 {ListboxWidgetCmd procedure, "selection" option} { 550 list [catch {.l select a b c d} msg] $msg 551} {1 {wrong # args: should be ".l selection option index ?index?"}} 552test listbox-3.95 {ListboxWidgetCmd procedure, "selection" option} { 553 list [catch {.l selection a bogus} msg] $msg 554} {1 {bad listbox index "bogus": must be active, anchor, end, @x,y, or a number}} 555test listbox-3.96 {ListboxWidgetCmd procedure, "selection" option} { 556 list [catch {.l selection a 0 lousy} msg] $msg 557} {1 {bad listbox index "lousy": must be active, anchor, end, @x,y, or a number}} 558test listbox-3.97 {ListboxWidgetCmd procedure, "selection" option} { 559 list [catch {.l selection anchor 0 0} msg] $msg 560} {1 {wrong # args: should be ".l selection anchor index"}} 561test listbox-3.98 {ListboxWidgetCmd procedure, "selection" option} { 562 list [.l selection anchor 5; .l index anchor] \ 563 [.l selection anchor 0; .l index anchor] 564} {5 0} 565test listbox-3.99 {ListboxWidgetCmd procedure, "selection" option} { 566 .l selection anchor -1 567 .l index anchor 568} {0} 569test listbox-3.100 {ListboxWidgetCmd procedure, "selection" option} { 570 .l selection anchor end 571 .l index anchor 572} {17} 573test listbox-3.101 {ListboxWidgetCmd procedure, "selection" option} { 574 .l selection anchor 44 575 .l index anchor 576} {17} 577test listbox-3.102 {ListboxWidgetCmd procedure, "selection" option} { 578 .l selection clear 0 end 579 .l selection set 2 8 580 .l selection clear 3 4 581 .l curselection 582} {2 5 6 7 8} 583test listbox-3.103 {ListboxWidgetCmd procedure, "selection" option} { 584 list [catch {.l selection includes 0 0} msg] $msg 585} {1 {wrong # args: should be ".l selection includes index"}} 586test listbox-3.104 {ListboxWidgetCmd procedure, "selection" option} { 587 .l selection clear 0 end 588 .l selection set 2 8 589 .l selection clear 4 590 list [.l selection includes 3] [.l selection includes 4] \ 591 [.l selection includes 5] 592} {1 0 1} 593test listbox-3.105 {ListboxWidgetCmd procedure, "selection" option} { 594 .l selection set 0 end 595 .l selection includes -1 596} {0} 597test listbox-3.106 {ListboxWidgetCmd procedure, "selection" option} { 598 .l selection clear 0 end 599 .l selection set end 600 .l selection includes end 601} {1} 602test listbox-3.107 {ListboxWidgetCmd procedure, "selection" option} { 603 .l selection set 0 end 604 .l selection includes 44 605} {0} 606test listbox-3.108 {ListboxWidgetCmd procedure, "selection" option} { 607 catch {destroy .l2} 608 listbox .l2 609 .l2 selection includes 0 610} {0} 611test listbox-3.109 {ListboxWidgetCmd procedure, "selection" option} { 612 .l selection clear 0 end 613 .l selection set 2 614 .l selection set 5 7 615 .l curselection 616} {2 5 6 7} 617test listbox-3.110 {ListboxWidgetCmd procedure, "selection" option} { 618 .l selection set 5 7 619 .l curselection 620} {2 5 6 7} 621test listbox-3.111 {ListboxWidgetCmd procedure, "selection" option} { 622 list [catch {.l selection badOption 0 0} msg] $msg 623} {1 {bad option "badOption": must be anchor, clear, includes, or set}} 624test listbox-3.112 {ListboxWidgetCmd procedure, "size" option} { 625 list [catch {.l size a} msg] $msg 626} {1 {wrong # args: should be ".l size"}} 627test listbox-3.113 {ListboxWidgetCmd procedure, "size" option} { 628 .l size 629} {18} 630test listbox-3.114 {ListboxWidgetCmd procedure, "xview" option} { 631 catch {destroy .l2} 632 listbox .l2 633 update 634 .l2 xview 635} {0 1} 636test listbox-3.115 {ListboxWidgetCmd procedure, "xview" option} { 637 catch {destroy .l} 638 listbox .l -width 10 -height 5 -font $fixed 639 .l insert 0 a b c d e f g h i j k l m n o p q r s t 640 pack .l 641 update 642 .l xview 643} {0 1} 644catch {destroy .l} 645listbox .l -width 10 -height 5 -font $fixed 646.l insert 0 a b c d e f g h i j k l m n o p q r s t 647.l insert 1 "0123456789a123456789b123456789c123456789d123456789" 648pack .l 649update 650test listbox-3.116 {ListboxWidgetCmd procedure, "xview" option} {fonts} { 651 .l xview 4 652 .l xview 653} {0.08 0.28} 654test listbox-3.117 {ListboxWidgetCmd procedure, "xview" option} { 655 list [catch {.l xview foo} msg] $msg 656} {1 {expected integer but got "foo"}} 657test listbox-3.118 {ListboxWidgetCmd procedure, "xview" option} { 658 list [catch {.l xview zoom a b} msg] $msg 659} {1 {unknown option "zoom": must be moveto or scroll}} 660test listbox-3.119 {ListboxWidgetCmd procedure, "xview" option} {fonts} { 661 .l xview 0 662 .l xview moveto .4 663 update 664 .l xview 665} {0.4 0.6} 666test listbox-3.120 {ListboxWidgetCmd procedure, "xview" option} {fonts} { 667 .l xview 0 668 .l xview scroll 2 units 669 update 670 .l xview 671} {0.04 0.24} 672test listbox-3.121 {ListboxWidgetCmd procedure, "xview" option} {fonts} { 673 .l xview 30 674 .l xview scroll -1 pages 675 update 676 .l xview 677} {0.44 0.64} 678test listbox-3.122 {ListboxWidgetCmd procedure, "xview" option} {fonts} { 679 .l configure -width 1 680 update 681 .l xview 30 682 .l xview scroll -4 pages 683 update 684 .l xview 685} {0.52 0.54} 686test listbox-3.123 {ListboxWidgetCmd procedure, "yview" option} { 687 catch {destroy .l} 688 listbox .l 689 pack .l 690 update 691 .l yview 692} {0 1} 693test listbox-3.124 {ListboxWidgetCmd procedure, "yview" option} { 694 catch {destroy .l} 695 listbox .l 696 .l insert 0 el1 697 pack .l 698 update 699 .l yview 700} {0 1} 701catch {destroy .l} 702listbox .l -width 10 -height 5 -font $fixed 703.l insert 0 a b c d e f g h i j k l m n o p q r s t 704pack .l 705update 706test listbox-3.125 {ListboxWidgetCmd procedure, "yview" option} { 707 .l yview 4 708 update 709 .l yview 710} {0.2 0.45} 711test listbox-3.126 {ListboxWidgetCmd procedure, "yview" option, partial last line} { 712 mkPartial 713 .partial.l yview 714} {0 0.266667} 715test listbox-3.127 {ListboxWidgetCmd procedure, "xview" option} { 716 list [catch {.l yview foo} msg] $msg 717} {1 {bad listbox index "foo": must be active, anchor, end, @x,y, or a number}} 718test listbox-3.128 {ListboxWidgetCmd procedure, "xview" option} { 719 list [catch {.l yview foo a b} msg] $msg 720} {1 {unknown option "foo": must be moveto or scroll}} 721test listbox-3.129 {ListboxWidgetCmd procedure, "xview" option} { 722 .l yview 0 723 .l yview moveto .31 724 .l yview 725} {0.3 0.55} 726test listbox-3.130 {ListboxWidgetCmd procedure, "xview" option} { 727 .l yview 2 728 .l yview scroll 2 pages 729 .l yview 730} {0.4 0.65} 731test listbox-3.131 {ListboxWidgetCmd procedure, "xview" option} { 732 .l yview 10 733 .l yview scroll -3 units 734 .l yview 735} {0.35 0.6} 736test listbox-3.132 {ListboxWidgetCmd procedure, "xview" option} { 737 .l configure -height 2 738 update 739 .l yview 15 740 .l yview scroll -4 pages 741 .l yview 742} {0.55 0.65} 743test listbox-3.133 {ListboxWidgetCmd procedure, "xview" option} { 744 list [catch {.l whoknows} msg] $msg 745} {1 {bad option "whoknows": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}} 746test listbox-3.134 {ListboxWidgetCmd procedure, "xview" option} { 747 list [catch {.l c} msg] $msg 748} {1 {ambiguous option "c": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}} 749test listbox-3.135 {ListboxWidgetCmd procedure, "xview" option} { 750 list [catch {.l in} msg] $msg 751} {1 {ambiguous option "in": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}} 752test listbox-3.136 {ListboxWidgetCmd procedure, "xview" option} { 753 list [catch {.l s} msg] $msg 754} {1 {ambiguous option "s": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}} 755test listbox-3.137 {ListboxWidgetCmd procedure, "xview" option} { 756 list [catch {.l se} msg] $msg 757} {1 {ambiguous option "se": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}} 758 759# No tests for DestroyListbox: I can't come up with anything to test 760# in this procedure. 761 762test listbox-4.1 {ConfigureListbox procedure} {fonts} { 763 catch {destroy .l} 764 listbox .l -setgrid 1 -width 25 -height 15 765 pack .l 766 update 767 set x [getsize .] 768 .l configure -setgrid 0 769 update 770 list $x [getsize .] 771} {25x15 185x263} 772resetGridInfo 773test listbox-4.2 {ConfigureListbox procedure} { 774 .l configure -highlightthickness -3 775 .l cget -highlightthickness 776} {0} 777test listbox-4.3 {ConfigureListbox procedure} { 778 .l configure -exportselection 0 779 .l delete 0 end 780 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 781 .l selection set 3 5 782 .l configure -exportselection 1 783 selection get 784} {el3 785el4 786el5} 787test listbox-4.4 {ConfigureListbox procedure} { 788 catch {destroy .e} 789 entry .e 790 .e insert 0 abc 791 .e select from 0 792 .e select to 2 793 .l configure -exportselection 0 794 .l delete 0 end 795 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 796 .l selection set 3 5 797 .l selection clear 3 5 798 .l configure -exportselection 1 799 list [selection own] [selection get] 800} {.e ab} 801test listbox-4.5 {-exportselection option} { 802 selection clear . 803 .l configure -exportselection 1 804 .l delete 0 end 805 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 806 .l selection set 1 1 807 set x {} 808 lappend x [catch {selection get} msg] $msg [.l curselection] 809 .l config -exportselection 0 810 lappend x [catch {selection get} msg] $msg [.l curselection] 811 .l selection clear 0 end 812 lappend x [catch {selection get} msg] $msg [.l curselection] 813 .l selection set 1 3 814 lappend x [catch {selection get} msg] $msg [.l curselection] 815 .l config -exportselection 1 816 lappend x [catch {selection get} msg] $msg [.l curselection] 817} {0 el1 1 1 {PRIMARY selection doesn't exist or form "STRING" not defined} 1 1 {PRIMARY selection doesn't exist or form "STRING" not defined} {} 1 {PRIMARY selection doesn't exist or form "STRING" not defined} {1 2 3} 0 {el1 818el2 819el3} {1 2 3}} 820test listbox-4.6 {ConfigureListbox procedure} {fonts} { 821 catch {destroy .l} 822 823 # The following code (reset geometry, withdraw, etc.) is necessary 824 # to reset the state of some window managers like olvwm under 825 # SunOS 4.1.3. 826 827 wm geom . 300x300 828 update 829 wm geom . {} 830 wm withdraw . 831 listbox .l -font $fixed -width 15 -height 20 832 pack .l 833 update 834 wm deiconify . 835 set x [getsize .] 836 .l configure -setgrid 1 837 update 838 list $x [getsize .] 839} {115x328 15x20} 840test listbox-4.7 {ConfigureListbox procedure} { 841 catch {destroy .l} 842 wm withdraw . 843 listbox .l -font $fixed -width 30 -height 20 -setgrid 1 844 wm geom . +25+25 845 pack .l 846 update 847 wm deiconify . 848 set result [getsize .] 849 wm geom . 26x15 850 update 851 lappend result [getsize .] 852 .l configure -setgrid 1 853 update 854 lappend result [getsize .] 855} {30x20 26x15 26x15} 856wm geom . {} 857catch {destroy .l} 858resetGridInfo 859test listbox-4.8 {ConfigureListbox procedure} { 860 catch {destroy .l} 861 listbox .l -width 15 -height 20 -xscrollcommand "record x" \ 862 -yscrollcommand "record y" 863 pack .l 864 update 865 .l configure -fg black 866 set log {} 867 update 868 set log 869} {{y 0 1} {x 0 1}} 870test listbox-4.9 {ConfigureListbox procedure, -listvar} { 871 catch {destroy .l} 872 set x [list a b c d] 873 listbox .l -listvar x 874 .l get 0 end 875} [list a b c d] 876test listbox-4.10 {ConfigureListbox, no listvar -> existing listvar} { 877 catch {destroy .l} 878 set x [list a b c d] 879 listbox .l 880 .l insert end 1 2 3 4 881 .l configure -listvar x 882 .l get 0 end 883} [list a b c d] 884test listbox-4.11 {ConfigureListbox procedure, listvar -> no listvar} { 885 catch {destroy .l} 886 set x [list a b c d] 887 listbox .l -listvar x 888 .l configure -listvar {} 889 .l insert end 1 2 3 4 890 list $x [.l get 0 end] 891} [list [list a b c d] [list a b c d 1 2 3 4]] 892test listbox-4.12 {ConfigureListbox procedure, listvar -> different listvar} { 893 catch {destroy .l} 894 set x [list a b c d] 895 set y [list 1 2 3 4] 896 listbox .l 897 .l configure -listvar x 898 .l configure -listvar y 899 .l insert end 5 6 7 8 900 list $x $y 901} [list [list a b c d] [list 1 2 3 4 5 6 7 8]] 902test listbox-4.13 {ConfigureListbox, no listvar -> non-existant listvar} { 903 catch {destroy .l} 904 catch {unset x} 905 listbox .l 906 .l insert end a b c d 907 .l configure -listvar x 908 set x 909} [list a b c d] 910test listbox-4.14 {ConfigureListbox, non-existant listvar} { 911 catch {destroy .l} 912 catch {unset x} 913 listbox .l -listvar x 914 list [info exists x] $x 915} [list 1 {}] 916test listbox-4.15 {ConfigureListbox, listvar -> non-existant listvar} { 917 catch {destroy .l} 918 catch {unset y} 919 set x [list a b c d] 920 listbox .l -listvar x 921 .l configure -listvar y 922 list [info exists y] $y 923} [list 1 [list a b c d]] 924test listbox-4.16 {ConfigureListbox, listvar -> same listvar} { 925 catch {destroy .l} 926 set x [list a b c d] 927 listbox .l -listvar x 928 .l configure -listvar x 929 set x 930} [list a b c d] 931test listbox-4.17 {ConfigureListbox, no listvar -> no listvar} { 932 catch {destroy .l} 933 listbox .l 934 .l insert end a b c d 935 .l configure -listvar {} 936 .l get 0 end 937} [list a b c d] 938test listbox-4.18 {ConfigureListbox, no listvar -> bad listvar} { 939 catch {destroy .l} 940 listbox .l 941 .l insert end a b c d 942 set x "this is a \" bad list" 943 catch {.l configure -listvar x} result 944 list [.l get 0 end] [.l cget -listvar] $result 945} [list [list a b c d] {} \ 946 "unmatched open quote in list: invalid -listvariable value"] 947test listbox-4.19 {ConfigureListbox, no listvar -> bad non-existent listvar} { 948 catch {destroy .l} 949 listbox .l -listvar foo 950 .l insert end a b c d 951 catch {.l configure -listvar ::zoo::bar::foo} result 952 list [.l get 0 end] [.l cget -listvar] $foo $result 953} [list [list a b c d] foo [list a b c d] \ 954 {can't set "::zoo::bar::foo": parent namespace doesn't exist}] 955 956# No tests for DisplayListbox: I don't know how to test this procedure. 957 958test listbox-5.1 {ListboxComputeGeometry procedure} {fonts} { 959 catch {destroy .l} 960 listbox .l -font $fixed -width 15 -height 20 961 pack .l 962 list [winfo reqwidth .l] [winfo reqheight .l] 963} {115 328} 964test listbox-5.2 {ListboxComputeGeometry procedure} {fonts} { 965 catch {destroy .l} 966 listbox .l -font $fixed -width 0 -height 10 967 pack .l 968 update 969 list [winfo reqwidth .l] [winfo reqheight .l] 970} {17 168} 971test listbox-5.3 {ListboxComputeGeometry procedure} {fonts} { 972 catch {destroy .l} 973 listbox .l -font $fixed -width 0 -height 10 -bd 3 974 .l insert 0 Short "Really much longer" Longer 975 pack .l 976 update 977 list [winfo reqwidth .l] [winfo reqheight .l] 978} {138 170} 979test listbox-5.4 {ListboxComputeGeometry procedure} {fonts} { 980 catch {destroy .l} 981 listbox .l -font $fixed -width 10 -height 0 982 pack .l 983 update 984 list [winfo reqwidth .l] [winfo reqheight .l] 985} {80 24} 986test listbox-5.5 {ListboxComputeGeometry procedure} {fonts} { 987 catch {destroy .l} 988 listbox .l -font $fixed -width 10 -height 0 -highlightthickness 0 989 .l insert 0 Short "Really much longer" Longer 990 pack .l 991 update 992 list [winfo reqwidth .l] [winfo reqheight .l] 993} {76 52} 994test listbox-5.6 {ListboxComputeGeometry procedure} { 995 # If "0" in selected font had 0 width, caused divide-by-zero error. 996 997 catch {destroy .l} 998 pack [listbox .l -font {{open look glyph}}] 999 update 1000} {} 1001 1002 1003catch {destroy .l} 1004listbox .l -height 2 -xscrollcommand "record x" -yscrollcommand "record y" 1005pack .l 1006update 1007test listbox-6.1 {InsertEls procedure} { 1008 .l delete 0 end 1009 .l insert end a b c d 1010 .l insert 5 x y z 1011 .l insert 2 A 1012 .l insert 0 q r s 1013 .l get 0 end 1014} {q r s a b A c d x y z} 1015test listbox-6.2 {InsertEls procedure} { 1016 .l delete 0 end 1017 .l insert 0 a b c d e f g h i j 1018 .l selection anchor 2 1019 .l insert 2 A B 1020 .l index anchor 1021} {4} 1022test listbox-6.3 {InsertEls procedure} { 1023 .l delete 0 end 1024 .l insert 0 a b c d e f g h i j 1025 .l selection anchor 2 1026 .l insert 3 A B 1027 .l index anchor 1028} {2} 1029test listbox-6.4 {InsertEls procedure} { 1030 .l delete 0 end 1031 .l insert 0 a b c d e f g h i j 1032 .l yview 3 1033 update 1034 .l insert 2 A B 1035 .l index @0,0 1036} {5} 1037test listbox-6.5 {InsertEls procedure} { 1038 .l delete 0 end 1039 .l insert 0 a b c d e f g h i j 1040 .l yview 3 1041 update 1042 .l insert 3 A B 1043 .l index @0,0 1044} {3} 1045test listbox-6.6 {InsertEls procedure} { 1046 .l delete 0 end 1047 .l insert 0 a b c d e f g h i j 1048 .l activate 5 1049 .l insert 5 A B 1050 .l index active 1051} {7} 1052test listbox-6.7 {InsertEls procedure} { 1053 .l delete 0 end 1054 .l insert 0 a b c d e f g h i j 1055 .l activate 5 1056 .l insert 6 A B 1057 .l index active 1058} {5} 1059test listbox-6.8 {InsertEls procedure} { 1060 .l delete 0 end 1061 .l insert 0 a b c 1062 .l index active 1063} {2} 1064test listbox-6.9 {InsertEls procedure} { 1065 .l delete 0 end 1066 .l insert 0 1067 .l index active 1068} {0} 1069test listbox-6.10 {InsertEls procedure} { 1070 .l delete 0 end 1071 .l insert 0 a b "two words" c d e f g h i j 1072 update 1073 set log {} 1074 .l insert 0 word 1075 update 1076 set log 1077} {{y 0 0.166667}} 1078test listbox-6.11 {InsertEls procedure} { 1079 .l delete 0 end 1080 .l insert 0 a b "two words" c d e f g h i j 1081 update 1082 set log {} 1083 .l insert 0 "much longer entry" 1084 update 1085 set log 1086} {{y 0 0.166667} {x 0 1}} 1087test listbox-6.12 {InsertEls procedure} {fonts} { 1088 catch {destroy .l2} 1089 listbox .l2 -width 0 -height 0 1090 pack .l2 -side top 1091 .l2 insert 0 a b "two words" c d 1092 set x {} 1093 lappend x [winfo reqwidth .l2] [winfo reqheight .l2] 1094 .l2 insert 0 "much longer entry" 1095 lappend x [winfo reqwidth .l2] [winfo reqheight .l2] 1096} {80 93 122 110} 1097test listbox-6.13 {InsertEls procedure, check -listvar update} { 1098 catch {destroy .l2} 1099 set x [list a b c d] 1100 listbox .l2 -listvar x 1101 .l2 insert 0 1 2 3 4 1102 set x 1103} [list 1 2 3 4 a b c d] 1104test listbox-6.14 {InsertEls procedure, check selection update} { 1105 catch {destroy .l2} 1106 listbox .l2 1107 .l2 insert 0 0 1 2 3 4 1108 .l2 selection set 2 4 1109 .l2 insert 0 a 1110 .l2 curselection 1111} [list 3 4 5] 1112test listbox-6.15 {InsertEls procedure, lost namespaced listvar, bug 1424513} { 1113 destroy .l2 1114 namespace eval test { variable foo {a b} } 1115 listbox .l2 -listvar ::test::foo 1116 namespace delete test 1117 .l2 insert end c d 1118 .l2 delete end 1119 .l2 insert end e f 1120 catch {set ::test::foo} result 1121 list [.l2 get 0 end] [.l2 cget -listvar] $result 1122} [list [list a b c e f] ::test::foo \ 1123 {can't read "::test::foo": no such variable}] 1124 1125 1126test listbox-7.1 {DeleteEls procedure} { 1127 .l delete 0 end 1128 .l insert 0 a b c d e f g h i j 1129 .l selection set 1 6 1130 .l delete 4 3 1131 list [.l size] [selection get] 1132} {10 {b 1133c 1134d 1135e 1136f 1137g}} 1138test listbox-7.2 {DeleteEls procedure} { 1139 .l delete 0 end 1140 .l insert 0 a b c d e f g h i j 1141 .l selection set 3 6 1142 .l delete 4 4 1143 list [.l size] [.l get 4] [.l curselection] 1144} {9 f {3 4 5}} 1145test listbox-7.3 {DeleteEls procedure} { 1146 .l delete 0 end 1147 .l insert 0 a b c d e f g h i j 1148 .l delete 0 3 1149 list [.l size] [.l get 0] [.l get 1] 1150} {6 e f} 1151test listbox-7.4 {DeleteEls procedure} { 1152 .l delete 0 end 1153 .l insert 0 a b c d e f g h i j 1154 .l delete 8 1000 1155 list [.l size] [.l get 7] 1156} {8 h} 1157test listbox-7.5 {DeleteEls procedure} { 1158 .l delete 0 end 1159 .l insert 0 a b c d e f g h i j 1160 .l selection anchor 2 1161 .l delete 0 1 1162 .l index anchor 1163} {0} 1164test listbox-7.6 {DeleteEls procedure} { 1165 .l delete 0 end 1166 .l insert 0 a b c d e f g h i j 1167 .l selection anchor 2 1168 .l delete 2 1169 .l index anchor 1170} {2} 1171test listbox-7.7 {DeleteEls procedure} { 1172 .l delete 0 end 1173 .l insert 0 a b c d e f g h i j 1174 .l selection anchor 4 1175 .l delete 2 5 1176 .l index anchor 1177} {2} 1178test listbox-7.8 {DeleteEls procedure} { 1179 .l delete 0 end 1180 .l insert 0 a b c d e f g h i j 1181 .l selection anchor 3 1182 .l delete 4 5 1183 .l index anchor 1184} {3} 1185test listbox-7.9 {DeleteEls procedure} { 1186 .l delete 0 end 1187 .l insert 0 a b c d e f g h i j 1188 .l yview 3 1189 update 1190 .l delete 1 2 1191 .l index @0,0 1192} {1} 1193test listbox-7.10 {DeleteEls procedure} { 1194 .l delete 0 end 1195 .l insert 0 a b c d e f g h i j 1196 .l yview 3 1197 update 1198 .l delete 3 4 1199 .l index @0,0 1200} {3} 1201test listbox-7.11 {DeleteEls procedure} { 1202 .l delete 0 end 1203 .l insert 0 a b c d e f g h i j 1204 .l yview 3 1205 update 1206 .l delete 4 6 1207 .l index @0,0 1208} {3} 1209test listbox-7.12 {DeleteEls procedure} { 1210 .l delete 0 end 1211 .l insert 0 a b c d e f g h i j 1212 .l yview 3 1213 update 1214 .l delete 3 end 1215 .l index @0,0 1216} {1} 1217test listbox-7.13 {DeleteEls procedure, updating view with partial last line} { 1218 mkPartial 1219 .partial.l yview 8 1220 update 1221 .partial.l delete 10 13 1222 .partial.l index @0,0 1223} {7} 1224test listbox-7.14 {DeleteEls procedure} { 1225 .l delete 0 end 1226 .l insert 0 a b c d e f g h i j 1227 .l activate 6 1228 .l delete 3 4 1229 .l index active 1230} {4} 1231test listbox-7.15 {DeleteEls procedure} { 1232 .l delete 0 end 1233 .l insert 0 a b c d e f g h i j 1234 .l activate 6 1235 .l delete 5 7 1236 .l index active 1237} {5} 1238test listbox-7.16 {DeleteEls procedure} { 1239 .l delete 0 end 1240 .l insert 0 a b c d e f g h i j 1241 .l activate 6 1242 .l delete 5 end 1243 .l index active 1244} {4} 1245test listbox-7.17 {DeleteEls procedure} { 1246 .l delete 0 end 1247 .l insert 0 a b c d e f g h i j 1248 .l activate 6 1249 .l delete 0 end 1250 .l index active 1251} {0} 1252test listbox-7.18 {DeleteEls procedure} { 1253 .l delete 0 end 1254 .l insert 0 a b c "two words" d e f g h i j 1255 update 1256 set log {} 1257 .l delete 4 6 1258 update 1259 set log 1260} {{y 0 0.25}} 1261test listbox-7.19 {DeleteEls procedure} { 1262 .l delete 0 end 1263 .l insert 0 a b c "two words" d e f g h i j 1264 update 1265 set log {} 1266 .l delete 3 1267 update 1268 set log 1269} {{y 0 0.2} {x 0 1}} 1270test listbox-7.20 {DeleteEls procedure} {fonts} { 1271 catch {destroy .l2} 1272 listbox .l2 -width 0 -height 0 1273 pack .l2 -side top 1274 .l2 insert 0 a b "two words" c d e f g 1275 set x {} 1276 lappend x [winfo reqwidth .l2] [winfo reqheight .l2] 1277 .l2 delete 2 4 1278 lappend x [winfo reqwidth .l2] [winfo reqheight .l2] 1279} {80 144 17 93} 1280catch {destroy .l2} 1281test listbox-7.21 {DeleteEls procedure, check -listvar update} { 1282 catch {destroy .l2} 1283 set x [list a b c d] 1284 listbox .l2 -listvar x 1285 .l2 delete 0 1 1286 set x 1287} [list c d] 1288 1289test listbox-8.1 {ListboxEventProc procedure} {fonts} { 1290 catch {destroy .l} 1291 listbox .l -setgrid 1 1292 pack .l 1293 update 1294 set x [getsize .] 1295 destroy .l 1296 list $x [getsize .] [winfo exists .l] [info command .l] 1297} {20x10 150x178 0 {}} 1298resetGridInfo 1299test listbox-8.2 {ListboxEventProc procedure} {fonts} { 1300 catch {destroy .l} 1301 listbox .l -height 5 -width 10 1302 .l insert 0 a b c "A string that is very very long" d e f g h i j k 1303 pack .l 1304 update 1305 place .l -width 50 -height 80 1306 update 1307 list [.l xview] [.l yview] 1308} {{0 0.222222} {0 0.333333}} 1309test listbox-8.3 {ListboxEventProc procedure} { 1310 deleteWindows 1311 listbox .l1 -bg #543210 1312 rename .l1 .l2 1313 set x {} 1314 lappend x [winfo children .] 1315 lappend x [.l2 cget -bg] 1316 destroy .l1 1317 lappend x [info command .l*] [winfo children .] 1318} {.l1 #543210 {} {}} 1319 1320test listbox-9.1 {ListboxCmdDeletedProc procedure} { 1321 deleteWindows 1322 listbox .l1 1323 rename .l1 {} 1324 list [info command .l*] [winfo children .] 1325} {{} {}} 1326test listbox-9.2 {ListboxCmdDeletedProc procedure, disabling -setgrid} fonts { 1327 catch {destroy .top} 1328 toplevel .top 1329 wm geom .top +0+0 1330 listbox .top.l -setgrid 1 -width 20 -height 10 1331 pack .top.l 1332 update 1333 set x [wm geometry .top] 1334 rename .top.l {} 1335 update 1336 lappend x [wm geometry .top] 1337 destroy .top 1338 set x 1339} {20x10+0+0 150x178+0+0} 1340 1341catch {destroy .l} 1342listbox .l 1343pack .l 1344.l delete 0 end 1345.l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11 1346test listbox-10.1 {GetListboxIndex procedure} { 1347 .l activate 3 1348 list [.l activate 3; .l index active] [.l activate 6; .l index active] 1349} {3 6} 1350test listbox-10.2 {GetListboxIndex procedure} { 1351 .l selection anchor 2 1352 .l index anchor 1353} 2 1354test listbox-10.3 {GetListboxIndex procedure} { 1355 .l insert end A B C D E 1356 .l selection anchor end 1357 .l delete 12 end 1358 list [.l index anchor] [.l index end] 1359} {12 12} 1360test listbox-10.4 {GetListboxIndex procedure} { 1361 list [catch {.l index a} msg] $msg 1362} {1 {bad listbox index "a": must be active, anchor, end, @x,y, or a number}} 1363test listbox-10.5 {GetListboxIndex procedure} { 1364 .l index end 1365} {12} 1366test listbox-10.6 {GetListboxIndex procedure} { 1367 .l get end 1368} {el11} 1369test listbox-10.7 {GetListboxIndex procedure} { 1370 .l delete 0 end 1371 .l index end 1372} 0 1373.l delete 0 end 1374.l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11 1375update 1376test listbox-10.8 {GetListboxIndex procedure} { 1377 list [catch {.l index @} msg] $msg 1378} {1 {bad listbox index "@": must be active, anchor, end, @x,y, or a number}} 1379test listbox-10.9 {GetListboxIndex procedure} { 1380 list [catch {.l index @foo} msg] $msg 1381} {1 {bad listbox index "@foo": must be active, anchor, end, @x,y, or a number}} 1382test listbox-10.10 {GetListboxIndex procedure} { 1383 list [catch {.l index @1x3} msg] $msg 1384} {1 {bad listbox index "@1x3": must be active, anchor, end, @x,y, or a number}} 1385test listbox-10.11 {GetListboxIndex procedure} { 1386 list [catch {.l index @1,} msg] $msg 1387} {1 {bad listbox index "@1,": must be active, anchor, end, @x,y, or a number}} 1388test listbox-10.12 {GetListboxIndex procedure} { 1389 list [catch {.l index @1,foo} msg] $msg 1390} {1 {bad listbox index "@1,foo": must be active, anchor, end, @x,y, or a number}} 1391test listbox-10.13 {GetListboxIndex procedure} { 1392 list [catch {.l index @1,2x} msg] $msg 1393} {1 {bad listbox index "@1,2x": must be active, anchor, end, @x,y, or a number}} 1394test listbox-10.14 {GetListboxIndex procedure} {fonts} { 1395 list [.l index @5,57] [.l index @5,58] 1396} {3 3} 1397test listbox-10.15 {GetListboxIndex procedure} { 1398 list [catch {.l index 1xy} msg] $msg 1399} {1 {bad listbox index "1xy": must be active, anchor, end, @x,y, or a number}} 1400test listbox-10.16 {GetListboxIndex procedure} { 1401 .l index 3 1402} {3} 1403test listbox-10.17 {GetListboxIndex procedure} { 1404 .l index 20 1405} {20} 1406test listbox-10.18 {GetListboxIndex procedure} { 1407 .l get 20 1408} {} 1409test listbox-10.19 {GetListboxIndex procedure} { 1410 .l index -2 1411} -2 1412test listbox-10.20 {GetListboxIndex procedure} { 1413 .l delete 0 end 1414 .l index 1 1415} 1 1416 1417test listbox-11.1 {ChangeListboxView procedure, boundary conditions for index} { 1418 catch {destroy .l} 1419 listbox .l -height 5 1420 pack .l 1421 .l insert 0 a b c d e f g h i j 1422 .l yview 3 1423 update 1424 set x [.l index @0,0] 1425 .l yview -1 1426 update 1427 lappend x [.l index @0,0] 1428} {3 0} 1429test listbox-11.2 {ChangeListboxView procedure, boundary conditions for index} { 1430 catch {destroy .l} 1431 listbox .l -height 5 1432 pack .l 1433 .l insert 0 a b c d e f g h i j 1434 .l yview 3 1435 update 1436 set x [.l index @0,0] 1437 .l yview 20 1438 update 1439 lappend x [.l index @0,0] 1440} {3 5} 1441test listbox-11.3 {ChangeListboxView procedure} { 1442 catch {destroy .l} 1443 listbox .l -height 5 -yscrollcommand "record y" 1444 pack .l 1445 .l insert 0 a b c d e f g h i j 1446 update 1447 set log {} 1448 .l yview 2 1449 update 1450 list [.l yview] $log 1451} {{0.2 0.7} {{y 0.2 0.7}}} 1452test listbox-11.4 {ChangeListboxView procedure} { 1453 catch {destroy .l} 1454 listbox .l -height 5 -yscrollcommand "record y" 1455 pack .l 1456 .l insert 0 a b c d e f g h i j 1457 update 1458 set log {} 1459 .l yview 8 1460 update 1461 list [.l yview] $log 1462} {{0.5 1} {{y 0.5 1}}} 1463test listbox-11.5 {ChangeListboxView procedure} { 1464 catch {destroy .l} 1465 listbox .l -height 5 -yscrollcommand "record y" 1466 pack .l 1467 .l insert 0 a b c d e f g h i j 1468 .l yview 3 1469 update 1470 set log {} 1471 .l yview 3 1472 update 1473 list [.l yview] $log 1474} {{0.3 0.8} {}} 1475test listbox-11.6 {ChangeListboxView procedure, partial last line} { 1476 mkPartial 1477 .partial.l yview 13 1478 .partial.l index @0,0 1479} {11} 1480 1481catch {destroy .l} 1482listbox .l -font $fixed -xscrollcommand "record x" -width 10 1483.l insert 0 0123456789a123456789b123456789c123456789d123456789e123456789f123456789g123456789h123456789i123456789 1484pack .l 1485update 1486test listbox-12.1 {ChangeListboxOffset procedure} {fonts} { 1487 set log {} 1488 .l xview 99 1489 update 1490 list [.l xview] $log 1491} {{0.9 1} {{x 0.9 1}}} 1492test listbox-12.2 {ChangeListboxOffset procedure} {fonts} { 1493 set log {} 1494 .l xview moveto -.25 1495 update 1496 list [.l xview] $log 1497} {{0 0.1} {{x 0 0.1}}} 1498test listbox-12.3 {ChangeListboxOffset procedure} {fonts} { 1499 .l xview 10 1500 update 1501 set log {} 1502 .l xview 10 1503 update 1504 list [.l xview] $log 1505} {{0.1 0.2} {}} 1506 1507catch {destroy .l} 1508listbox .l -font $fixed -width 10 -height 5 1509pack .l 1510.l insert 0 a bb c d e f g h i j k l m n o p q r s 1511.l insert 0 0123456789a123456789b123456789c123456789d123456789 1512update 1513set width [expr [lindex [.l bbox 2] 2] - [lindex [.l bbox 1] 2]] 1514set height [expr [lindex [.l bbox 2] 1] - [lindex [.l bbox 1] 1]] 1515test listbox-13.1 {ListboxScanTo procedure} {fonts} { 1516 .l yview 0 1517 .l xview 0 1518 .l scan mark 10 20 1519 .l scan dragto [expr 10-$width] [expr 20-$height] 1520 update 1521 list [.l xview] [.l yview] 1522} {{0.2 0.4} {0.5 0.75}} 1523test listbox-13.2 {ListboxScanTo procedure} {fonts} { 1524 .l yview 5 1525 .l xview 10 1526 .l scan mark 10 20 1527 .l scan dragto 20 40 1528 update 1529 set x [list [.l xview] [.l yview]] 1530 .l scan dragto [expr 20-$width] [expr 40-$height] 1531 update 1532 lappend x [.l xview] [.l yview] 1533} {{0 0.2} {0 0.25} {0.2 0.4} {0.5 0.75}} 1534test listbox-13.3 {ListboxScanTo procedure} {fonts} { 1535 .l yview moveto 1.0 1536 .l xview moveto 1.0 1537 .l scan mark 10 20 1538 .l scan dragto 5 10 1539 update 1540 set x [list [.l xview] [.l yview]] 1541 .l scan dragto [expr 5+$width] [expr 10+$height] 1542 update 1543 lappend x [.l xview] [.l yview] 1544} {{0.8 1} {0.75 1} {0.64 0.84} {0.25 0.5}} 1545 1546test listbox-14.1 {NearestListboxElement procedure, partial last line} { 1547 mkPartial 1548 .partial.l nearest [winfo height .partial.l] 1549} {4} 1550catch {destroy .l} 1551listbox .l -font $fixed -width 20 -height 10 1552.l insert 0 a b c d e f g h i j k l m n o p q r s t 1553.l yview 4 1554pack .l 1555update 1556test listbox-14.2 {NearestListboxElement procedure} {fonts} { 1557 .l index @50,0 1558} {4} 1559test listbox-14.3 {NearestListboxElement procedure} {fonts} { 1560 list [.l index @50,35] [.l index @50,36] 1561} {5 6} 1562test listbox-14.4 {NearestListboxElement procedure} {fonts} { 1563 .l index @50,200 1564} {13} 1565 1566test listbox-15.1 {ListboxSelect procedure} { 1567 .l delete 0 end 1568 .l insert 0 a b c d e f g h i j k l m n o p 1569 .l select set 2 4 1570 .l select set 7 12 1571 .l select clear 4 7 1572 .l curselection 1573} {2 3 8 9 10 11 12} 1574test listbox-15.2 {ListboxSelect procedure} { 1575 .l delete 0 end 1576 .l insert 0 a b c d e f g h i j k l m n o p 1577 catch {destroy .e} 1578 entry .e 1579 .e insert 0 "This is some text" 1580 .e select from 0 1581 .e select to 7 1582 .l selection clear 2 4 1583 set x [selection own] 1584 .l selection set 3 1585 list $x [selection own] [selection get] 1586} {.e .l d} 1587test listbox-15.3 {ListboxSelect procedure} { 1588 .l delete 0 end 1589 .l selection clear 0 end 1590 .l select set 0 end 1591 .l curselection 1592} {} 1593test listbox-15.4 {ListboxSelect procedure, boundary conditions for indices} { 1594 .l delete 0 end 1595 .l insert 0 a b c d e f 1596 .l select clear 0 end 1597 .l select set -2 -1 1598 .l curselection 1599} {} 1600test listbox-15.5 {ListboxSelect procedure, boundary conditions for indices} { 1601 .l delete 0 end 1602 .l insert 0 a b c d e f 1603 .l select clear 0 end 1604 .l select set -1 3 1605 .l curselection 1606} {0 1 2 3} 1607test listbox-15.6 {ListboxSelect procedure, boundary conditions for indices} { 1608 .l delete 0 end 1609 .l insert 0 a b c d e f 1610 .l select clear 0 end 1611 .l select set 2 4 1612 .l curselection 1613} {2 3 4} 1614test listbox-15.7 {ListboxSelect procedure, boundary conditions for indices} { 1615 .l delete 0 end 1616 .l insert 0 a b c d e f 1617 .l select clear 0 end 1618 .l select set 4 end 1619 .l curselection 1620} {4 5} 1621test listbox-15.8 {ListboxSelect procedure, boundary conditions for indices} { 1622 .l delete 0 end 1623 .l insert 0 a b c d e f 1624 .l select clear 0 end 1625 .l select set 4 30 1626 .l curselection 1627} {4 5} 1628test listbox-15.9 {ListboxSelect procedure, boundary conditions for indices} { 1629 .l delete 0 end 1630 .l insert 0 a b c d e f 1631 .l select clear 0 end 1632 .l select set end 30 1633 .l curselection 1634} {5} 1635test listbox-15.10 {ListboxSelect procedure, boundary conditions for indices} { 1636 .l delete 0 end 1637 .l insert 0 a b c d e f 1638 .l select clear 0 end 1639 .l select set 20 25 1640 .l curselection 1641} {} 1642 1643test listbox-16.1 {ListboxFetchSelection procedure} { 1644 .l delete 0 end 1645 .l insert 0 a b c "two words" e f g h i \\ k l m n o p 1646 .l selection set 2 4 1647 .l selection set 9 1648 .l selection set 11 12 1649 selection get 1650} "c\ntwo words\ne\n\\\nl\nm" 1651test listbox-16.2 {ListboxFetchSelection procedure} { 1652 .l delete 0 end 1653 .l insert 0 a b c "two words" e f g h i \\ k l m n o p 1654 .l selection set 3 1655 selection get 1656} "two words" 1657test listbox-16.3 {ListboxFetchSelection procedure, retrieve in several parts} { 1658 set long "This is quite a long string\n" 1659 append long $long $long $long $long 1660 append long $long $long $long $long 1661 append long $long $long 1662 .l delete 0 end 1663 .l insert 0 1$long 2$long 3$long 4$long 5$long 1664 .l selection set 0 end 1665 set sel [selection get] 1666 string compare 1$long\n2$long\n3$long\n4$long\n5$long $sel 1667} {0} 1668catch {unset long sel} 1669 1670test listbox-17.1 {ListboxLostSelection procedure} { 1671 .l delete 0 end 1672 .l insert 0 a b c d e 1673 .l select set 0 end 1674 catch {destroy .e} 1675 entry .e 1676 .e insert 0 "This is some text" 1677 .e select from 0 1678 .e select to 5 1679 .l curselection 1680} {} 1681test listbox-17.2 {ListboxLostSelection procedure} { 1682 .l delete 0 end 1683 .l insert 0 a b c d e 1684 .l select set 0 end 1685 .l configure -exportselection 0 1686 catch {destroy .e} 1687 entry .e 1688 .e insert 0 "This is some text" 1689 .e select from 0 1690 .e select to 5 1691 .l curselection 1692} {0 1 2 3 4} 1693 1694catch {destroy .l} 1695listbox .l -font $fixed -width 10 -height 5 1696pack .l 1697update 1698test listbox-18.1 {ListboxUpdateVScrollbar procedure} { 1699 .l configure -yscrollcommand "record y" 1700 set log {} 1701 .l insert 0 a b c 1702 update 1703 .l insert end d e f g h 1704 update 1705 .l delete 0 end 1706 update 1707 set log 1708} {{y 0 1} {y 0 0.625} {y 0 1}} 1709test listbox-18.2 {ListboxUpdateVScrollbar procedure, partial last line} { 1710 mkPartial 1711 .partial.l configure -yscrollcommand "record y" 1712 set log {} 1713 .partial.l yview 3 1714 update 1715 set log 1716} {{y 0.2 0.466667}} 1717test listbox-18.3 {ListboxUpdateVScrollbar procedure} { 1718 proc bgerror args { 1719 global x errorInfo 1720 set x [list $args $errorInfo] 1721 } 1722 .l configure -yscrollcommand gorp 1723 .l insert 0 foo 1724 update 1725 set x 1726} {{{invalid command name "gorp"}} {invalid command name "gorp" 1727 while executing 1728"gorp 0 1" 1729 (vertical scrolling command executed by listbox)}} 1730if {[info exists bgerror]} { 1731 rename bgerror {} 1732} 1733 1734catch {destroy .l} 1735listbox .l -font $fixed -width 10 -height 5 1736pack .l 1737update 1738test listbox-19.1 {ListboxUpdateVScrollbar procedure} {fonts} { 1739 .l configure -xscrollcommand "record x" 1740 set log {} 1741 .l insert 0 abc 1742 update 1743 .l insert 0 "This is a much longer string..." 1744 update 1745 .l delete 0 end 1746 update 1747 set log 1748} {{x 0 1} {x 0 0.322581} {x 0 1}} 1749test listbox-19.2 {ListboxUpdateVScrollbar procedure} { 1750 proc bgerror args { 1751 global x errorInfo 1752 set x [list $args $errorInfo] 1753 } 1754 .l configure -xscrollcommand bogus 1755 .l insert 0 foo 1756 update 1757 set x 1758} {{{invalid command name "bogus"}} {invalid command name "bogus" 1759 while executing 1760"bogus 0 1" 1761 (horizontal scrolling command executed by listbox)}} 1762 1763set l [interp hidden] 1764deleteWindows 1765 1766test listbox-20.1 {listbox vs hidden commands} { 1767 catch {destroy .l} 1768 listbox .l 1769 interp hide {} .l 1770 destroy .l 1771 list [winfo children .] [interp hidden] 1772} [list {} $l] 1773 1774# tests for ListboxListVarProc 1775test listbox-21.1 {ListboxListVarProc} { 1776 catch {destroy .l} 1777 catch {unset x} 1778 listbox .l -listvar x 1779 set x [list a b c d] 1780 .l get 0 end 1781} [list a b c d] 1782test listbox-21.2 {ListboxListVarProc} { 1783 catch {destroy .l} 1784 set x [list a b c d] 1785 listbox .l -listvar x 1786 unset x 1787 set x 1788} [list a b c d] 1789test listbox-21.3 {ListboxListVarProc} { 1790 catch {destroy .l} 1791 set x [list a b c d] 1792 listbox .l -listvar x 1793 .l configure -listvar {} 1794 unset x 1795 info exists x 1796} 0 1797test listbox-21.4 {ListboxListVarProc} { 1798 catch {destroy .l} 1799 set x [list a b c d] 1800 listbox .l -listvar x 1801 lappend x e f g 1802 .l size 1803} 7 1804test listbox-21.5 {ListboxListVarProc, test selection after listvar mod} { 1805 catch {destroy .l} 1806 set x [list a b c d e f g] 1807 listbox .l -listvar x 1808 .l selection set end 1809 set x [list a b c d] 1810 set x [list 0 1 2 3 4 5 6] 1811 .l curselection 1812} {} 1813test listbox-21.6 {ListboxListVarProc, test selection after listvar mod} { 1814 catch {destroy .l} 1815 set x [list a b c d] 1816 listbox .l -listvar x 1817 .l selection set 3 1818 lappend x e f g 1819 .l curselection 1820} 3 1821test listbox-21.7 {ListboxListVarProc, test selection after listvar mod} { 1822 catch {destroy .l} 1823 set x [list a b c d] 1824 listbox .l -listvar x 1825 .l selection set 0 1826 set x [linsert $x 0 1 2 3 4] 1827 .l curselection 1828} 0 1829test listbox-21.8 {ListboxListVarProc, test selection after listvar mod} { 1830 catch {destroy .l} 1831 set x [list a b c d] 1832 listbox .l -listvar x 1833 .l selection set 2 1834 set x [list a b c] 1835 .l curselection 1836} 2 1837test listbox-21.9 {ListboxListVarProc, test hscrollbar after listvar mod} { 1838 catch {destroy .l} 1839 catch {unset x} 1840 set log {} 1841 listbox .l -font $fixed -width 10 -xscrollcommand "record x" -listvar x 1842 pack .l 1843 update 1844 lappend x "0000000000" 1845 update 1846 lappend x "00000000000000000000" 1847 update 1848 set log 1849} [list {x 0 1} {x 0 1} {x 0 0.5}] 1850test listbox-21.10 {ListboxListVarProc, test hscrollbar after listvar mod} { 1851 catch {destroy .l} 1852 catch {unset x} 1853 set log {} 1854 listbox .l -font $fixed -width 10 -xscrollcommand "record x" -listvar x 1855 pack .l 1856 update 1857 lappend x "0000000000" 1858 update 1859 lappend x "00000000000000000000" 1860 update 1861 set x [list "0000000000"] 1862 update 1863 set log 1864} [list {x 0 1} {x 0 1} {x 0 0.5} {x 0 1}] 1865test listbox-21.11 {ListboxListVarProc, bad list} { 1866 catch {destroy .l} 1867 catch {unset x} 1868 listbox .l -listvar x 1869 set x [list a b c d] 1870 catch {set x "this is a \" bad list"} result 1871 set result 1872} {can't set "x": invalid listvar value} 1873test listbox-21.12 {ListboxListVarProc, cleanup item attributes} { 1874 catch {destroy .l} 1875 set x [list a b c d e f g] 1876 listbox .l -listvar x 1877 .l itemconfigure end -fg red 1878 set x [list a b c d] 1879 set x [list 0 1 2 3 4 5 6] 1880 .l itemcget end -fg 1881} {} 1882test listbox-21.12 {ListboxListVarProc, cleanup item attributes} { 1883 catch {destroy .l} 1884 set x [list a b c d e f g] 1885 listbox .l -listvar x 1886 .l itemconfigure end -fg red 1887 set x [list a b c d] 1888 set x [list 0 1 2 3 4 5 6] 1889 .l itemcget end -fg 1890} {} 1891test listbox-21.13 {listbox item configurations and listvar based deletions} { 1892 catch {destroy .l} 1893 catch {unset x} 1894 listbox .l -listvar x 1895 .l insert end a b c 1896 .l itemconfigure 1 -fg red 1897 set x [list b c] 1898 .l itemcget 1 -fg 1899} red 1900test listbox-21.14 {listbox item configurations and listvar based inserts} { 1901 catch {destroy .l} 1902 catch {unset x} 1903 listbox .l -listvar x 1904 .l insert end a b c 1905 .l itemconfigure 0 -fg red 1906 set x [list 1 2 3 4 a b c] 1907 .l itemcget 0 -fg 1908} red 1909test listbox-21.15 {ListboxListVarProc, update vertical scrollbar} { 1910 catch {destroy .l} 1911 catch {unset x} 1912 set log {} 1913 listbox .l -listvar x -yscrollcommand "record y" -font fixed -height 3 1914 pack .l 1915 update 1916 lappend x a b c d e f 1917 update 1918 set log 1919} [list {y 0 1} {y 0 0.5}] 1920test listbox-21.16 {ListboxListVarProc, update vertical scrollbar} { 1921 catch {destroy .l} 1922 catch {unset x} 1923 listbox .l -listvar x -height 3 1924 pack .l 1925 update 1926 set x [list 0 1 2 3 4 5] 1927 .l yview scroll 3 units 1928 update 1929 set result {} 1930 lappend result [.l yview] 1931 set x [lreplace $x 3 3] 1932 set x [lreplace $x 3 3] 1933 set x [lreplace $x 3 3] 1934 update 1935 lappend result [.l yview] 1936 set result 1937} [list {0.5 1} {0 1}] 1938 1939# UpdateHScrollbar 1940test listbox-22.1 {UpdateHScrollbar} { 1941 catch {destroy .l} 1942 set log {} 1943 listbox .l -font $fixed -width 10 -xscrollcommand "record x" 1944 pack .l 1945 update 1946 .l insert end "0000000000" 1947 update 1948 .l insert end "00000000000000000000" 1949 update 1950 set log 1951} [list {x 0 1} {x 0 1} {x 0 0.5}] 1952 1953# ConfigureListboxItem 1954test listbox-23.1 {ConfigureListboxItem} { 1955 catch {destroy .l} 1956 listbox .l 1957 catch {.l itemconfigure 0} result 1958 set result 1959} {item number "0" out of range} 1960test listbox-23.2 {ConfigureListboxItem} { 1961 catch {destroy .l} 1962 listbox .l 1963 .l insert end a b c d 1964 .l itemconfigure 0 1965} [list {-background background Background {} {}} \ 1966 {-bg -background} \ 1967 {-fg -foreground} \ 1968 {-foreground foreground Foreground {} {}} \ 1969 {-selectbackground selectBackground Foreground {} {}} \ 1970 {-selectforeground selectForeground Background {} {}}] 1971test listbox-23.3 {ConfigureListboxItem, itemco shortcut} { 1972 catch {destroy .l} 1973 listbox .l 1974 .l insert end a b c d 1975 .l itemco 0 -background 1976} {-background background Background {} {}} 1977test listbox-23.4 {ConfigureListboxItem, wrong num args} { 1978 catch {destroy .l} 1979 listbox .l 1980 .l insert end a 1981 catch {.l itemco} result 1982 set result 1983} {wrong # args: should be ".l itemconfigure index ?option? ?value? ?option value ...?"} 1984test listbox-23.5 {ConfigureListboxItem, multiple calls} { 1985 catch {destroy .l} 1986 listbox .l 1987 set i 0 1988 foreach color {red orange yellow green blue white violet} { 1989 .l insert end $color 1990 .l itemconfigure $i -bg $color 1991 incr i 1992 } 1993 pack .l 1994 update 1995 list [.l itemcget 0 -bg] [.l itemcget 1 -bg] [.l itemcget 2 -bg] \ 1996 [.l itemcget 3 -bg] [.l itemcget 4 -bg] [.l itemcget 5 -bg] \ 1997 [.l itemcget 6 -bg] 1998} {red orange yellow green blue white violet} 1999catch {destroy .l} 2000listbox .l 2001.l insert end a b c d 2002set i 6 2003foreach test { 2004 {-background #ff0000 #ff0000 non-existent 2005 {unknown color name "non-existent"}} 2006 {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}} 2007 {-fg #110022 #110022 bogus {unknown color name "bogus"}} 2008 {-foreground #110022 #110022 bogus {unknown color name "bogus"}} 2009 {-selectbackground #110022 #110022 bogus {unknown color name "bogus"}} 2010 {-selectforeground #654321 #654321 bogus {unknown color name "bogus"}} 2011} { 2012 set name [lindex $test 0] 2013 test listbox-23.$i {configuration options} { 2014 .l itemconfigure 0 $name [lindex $test 1] 2015 list [lindex [.l itemconfigure 0 $name] 4] [.l itemcget 0 $name] 2016 } [list [lindex $test 2] [lindex $test 2]] 2017 incr i 2018 if {[lindex $test 3] != ""} { 2019 test listbox-23.$i {configuration options} { 2020 list [catch {.l configure $name [lindex $test 3]} msg] $msg 2021 } [list 1 [lindex $test 4]] 2022 } 2023 .l configure $name [lindex [.l configure $name] 3] 2024 incr i 2025} 2026 2027# ListboxWidgetObjCmd, itemcget 2028test listbox-24.1 {itemcget} { 2029 catch {destroy .l} 2030 listbox .l 2031 .l insert end a b c d 2032 .l itemcget 0 -fg 2033} {} 2034test listbox-24.2 {itemcget} { 2035 catch {destroy .l} 2036 listbox .l 2037 .l insert end a b c d 2038 .l itemconfigure 0 -fg red 2039 .l itemcget 0 -fg 2040} red 2041test listbox-24.3 {itemcget} { 2042 catch {destroy .l} 2043 listbox .l 2044 .l insert end a b c d 2045 catch {.l itemcget 0} result 2046 set result 2047} {wrong # args: should be ".l itemcget index option"} 2048test listbox-24.3 {itemcget, itemcg shortcut} { 2049 catch {destroy .l} 2050 listbox .l 2051 .l insert end a b c d 2052 catch {.l itemcg 0} result 2053 set result 2054} {wrong # args: should be ".l itemcget index option"} 2055 2056# General item configuration issues 2057test listbox-25.1 {listbox item configurations and widget based deletions} { 2058 catch {destroy .l} 2059 listbox .l 2060 .l insert end a 2061 .l itemconfigure 0 -fg red 2062 .l delete 0 end 2063 .l insert end a 2064 .l itemcget 0 -fg 2065} {} 2066test listbox-25.2 {listbox item configurations and widget based inserts} { 2067 catch {destroy .l} 2068 listbox .l 2069 .l insert end a b c 2070 .l itemconfigure 0 -fg red 2071 .l insert 0 1 2 3 4 2072 list [.l itemcget 0 -fg] [.l itemcget 4 -fg] 2073} [list {} red] 2074 2075# state issues 2076test listbox-26.1 {listbox disabled state disallows inserts} { 2077 catch {destroy .l} 2078 listbox .l 2079 .l insert end a b c 2080 .l configure -state disabled 2081 .l insert end d e f 2082 .l get 0 end 2083} [list a b c] 2084test listbox-26.2 {listbox disabled state disallows deletions} { 2085 catch {destroy .l} 2086 listbox .l 2087 .l insert end a b c 2088 .l configure -state disabled 2089 .l delete 0 end 2090 .l get 0 end 2091} [list a b c] 2092test listbox-26.3 {listbox disabled state disallows selection modification} { 2093 catch {destroy .l} 2094 listbox .l 2095 .l insert end a b c 2096 .l selection set 0 2097 .l selection set 2 2098 .l configure -state disabled 2099 .l selection clear 0 end 2100 .l selection set 1 2101 .l curselection 2102} [list 0 2] 2103test listbox-26.4 {listbox disabled state disallows anchor modification} { 2104 catch {destroy .l} 2105 listbox .l 2106 .l insert end a b c 2107 .l selection anchor 0 2108 .l configure -state disabled 2109 .l selection anchor 2 2110 .l index anchor 2111} 0 2112test listbox-26.5 {listbox disabled state disallows active modification} { 2113 catch {destroy .l} 2114 listbox .l 2115 .l insert end a b c 2116 .l activate 0 2117 .l configure -state disabled 2118 .l activate 2 2119 .l index active 2120} 0 2121 2122test listbox-27.1 {widget deletion while active} { 2123 destroy .l 2124 pack [listbox .l] 2125 update 2126 .l configure -cursor xterm -xscrollcommand { destroy .l } 2127 update idle 2128 winfo exists .l 2129} 0 2130 2131test listbox-28.1 {listbox -activestyle} { 2132 catch {destroy .l} 2133 listbox .l -activ non 2134 .l cget -activestyle 2135} none 2136test listbox-28.2 {listbox -activestyle} { 2137 catch {destroy .l} 2138 listbox .l 2139 .l cget -activestyle 2140} underline 2141test listbox-28.3 {listbox -activestyle} { 2142 catch {destroy .l} 2143 listbox .l -activestyle dot 2144 .l cget -activestyle 2145} dotbox 2146 2147test listbox-29.1 {listbox selection behavior, -state disabled} { 2148 destroy .l 2149 listbox .l 2150 .l insert end 1 2 3 2151 .l selection set 2 2152 set out [.l selection includes 2] 2153 .l configure -state disabled 2154 # still return 1 when disabled, because 'selection get' will work, 2155 # but selection cannot be changed (new behavior since 8.4) 2156 .l selection set 3 2157 lappend out [.l selection includes 2] [.l curselection] 2158} {1 1 2} 2159 2160resetGridInfo 2161deleteWindows 2162option clear 2163 2164# cleanup 2165::tcltest::cleanupTests 2166return 2167