home *** CD-ROM | disk | FTP | other *** search
- # CVS $Id: list.tcl,v 1.4 1995/04/28 11:40:43 zibi Exp $
- #
- # simple smoke test of list
- #
-
- global DisplayTxt
-
- proc display {delay args} {
- global DisplayTxt
-
- VtSetValues $DisplayTxt -value [join $args]
- if {$delay > 0} {sleep $delay}
- }
-
- proc quitCB {cbs} {
- VtClose
- exit 0
- }
-
- #
- # Sets the selectio style of the list widget
- #
- proc setStyleCB {lst style cbs} {
- set target [keylget cbs widget]
-
- display 0 $style
- VtSetValues $lst -selection $style
- VtDestroyDialog $target
- }
-
- #
- # Displays the selected items
- #
- proc selectCB {cbs} {
- display 0 "Widget is (" [keylget cbs widget] ")\n" \
- "Selected Items are " [keylget cbs selectedItemList]
- }
-
- #
- # Displays the items after a double click
- #
- proc defaultCB {cbs} {
- display 0 "You double clicked on Widget (" [lindex $cbs 0] ")\n" \
- "item is (" [lindex $cbs 1]
- }
-
- proc selectStyleCB {lst cbs} {
- set fn [VtStartForm $lst.tmp ]
- set chx [VtRadioBox $fn.chx]
- VtToggleButton $chx.single -label Single \
- -callback "setStyleCB $lst SINGLE"
- VtToggleButton $chx.extended -label Extended \
- -callback "setStyleCB $lst EXTENDED"
- VtToggleButton $chx.multiple -label Multiple \
- -callback "setStyleCB $lst MULTIPLE"
- VtToggleButton $chx.browse -label Browse \
- -callback "setStyleCB $lst BROWSE"
-
- VtShow $fn
- }
-
- proc restoreList {lst} {
- VtListDeleteItem $lst -all
- VtListAddItem $lst \
- -itemList {first second third fourth fifth sixth seventh}
- VtSetValues $lst -scrollBar 0
- }
-
- #
- # This test setting of the topItemPosition
- #
- proc testTopItemCB {lst cbs} {
- restoreList $lst
-
- set rows [VtGetValues $lst -rows]
-
- for {set i 1} { $i < $rows } {incr i} {
- VtSetValues $lst -topItemPosition $i
- set ret [VtGetValues $lst -topItemPosition]
- display 1 "Setting top to $i"
- if { $i != $ret } {
- error "Top Item Broken i is $i ret is $ret"
- }
- }
-
- sleep 1
-
- for {set i $rows} { $i > 0 } {incr i -1} {
- display 1 "Setting top to $i"
- VtSetValues $lst -topItemPosition $i
- }
-
- display 0 "Done, Testing topItemPosition"
- }
-
- proc testGetSelCB {lst cbs} {
- display 1 "List Get Test ..."
-
- restoreList $lst
-
- VtSetValues $lst -selection EXTENDED
-
- VtListSelectItem $lst -itemList {{ten 4} {five}}
- display 1 "Selecting bogus items {{ten 4} {five}}"
- set sel ""
- set sel [VtListGetSelectedItem $lst -byItemList]
- display 2 "Get selected items by items.."
- display 2 "** Got <<$sel>> **"
-
- VtListSelectItem $lst -itemList {{first 1} {second 2}}
- display 1 "Selecting by item, {{first 1} {second2}} "
-
- set sel [VtListGetSelectedItem $lst -byItemList]
- display 2 "Get selected items by items.."
- display 2 "** Got <<$sel>> **"
-
- VtListSelectItem $lst -positionList {1 3}
- display 2 "Selecting by positionList {1 3}"
-
- set sel [VtListGetSelectedItem $lst -byPositionList]
- display 2 "Get selected items by position.."
- display 2 "** Got <<$sel>> **"
-
- display 2 "Testing a get with nothing selected, both ways.."
- VtListDeselectItem $lst -all
- set sel [VtListGetSelectedItem $lst -byItemList]
- if {$sel == ""} {
- display 2 "byItemList returned nothing"
- } else {
- display 2 "***** <<$sel>> *****"
- }
-
- set sel [VtListGetSelectedItem $lst -byPositionList]
- if {$sel == ""} {
- display 2 "byPositionList returned nothing"
- } else {
- display 2 "***** <<$sel>> *****"
- }
-
- echo "me [VtListGetItem $lst -position 1 ]"
-
- display 0 "Done."
- }
-
- proc testGetCB {lst cbs} {
- display 1 "List Get Test ..."
-
- restoreList $lst
-
- set itemList [VtListGetItem $lst -position 1]
- display 1 "Getting item position 1 <$itemList>"
-
- set itemList [VtListGetItem $lst -position 0]
- display 1 "Getting item position 0 <$itemList>"
-
- display 7 "Getting item position 7 <$itemList>"
-
- set itemList [VtListGetItem $lst -positionList {0 2 3 7}]
-
- display 1 "Getting item position 0 2 3 7 <$itemList>"
-
- set itemList [VtListGetItem $lst -all]
-
- display 1 "Getting all item positions <$itemList>"
-
- display 0 "Done."
- }
-
- proc testDSelectCB {lst cbs} {
-
- restoreList $lst
-
- display 2 "Select all then deselect one by one by item"
- VtListSelectItem $lst -all
-
- foreach i {first second third fourth fifth} {
- display 1 " Deselecting item $i"
- VtListDeselectItem $lst -item $i
- }
-
- display 2 "Select all then deselect one by one by Position"
- VtListSelectItem $lst -all
-
- foreach i {1 2 3 4 5} {
- display 1 " Deselecting position $i"
- VtListDeselectItem $lst -position $i
- }
-
- display 2 "Select all then deselect by item List odd numbers "
- VtListSelectItem $lst -all
- VtListDeselectItem $lst -itemList {first third fifth}
- display 2 " first third and fifth shouldn't be selected"
-
- display 2 "Select all then deselect by item position even numbers"
- VtListSelectItem $lst -all
- VtListDeselectItem $lst -positionList {2 4}
- display 2 " second and fourth shouldn't be selected"
-
- VtListDeselectItem $lst -all
-
- display 0 done
- }
-
- proc testSelectCB {lst cbs} {
-
- restoreList $lst
- display 1 "List Select Test..."
-
- for {set i 1} {$i<=5} {incr i} {
- display 0 "selecting $i"
- VtListSelectItem $lst -position $i
- }
-
- VtSetValues $lst -selection EXTENDED
- VtListSelectItem $lst -positionList {1 3}
- display 2 "Selecting by positionList {1 3}"
-
- VtListSelectItem $lst -itemList {first fifth}
- display 2 "Selection by itemList {first fifth}"
-
- VtListSelectItem $lst -all
- display 2 "Selection -all"
-
- restoreList $lst
- display 0 "Done testing select."
- }
-
- proc testAddCB {lst cbs} {
- display 2 "Deleting all items"
- VtListDeleteItem $lst -all
-
-
- display 2 "Adding initial items, all at once."
- VtListAddItem $lst -itemList {"Initial 1" "Initial 2" "Initial 3" last}
-
- display 2 "Adding more items"
- foreach i {one two three four} {
- VtListAddItem $lst -position 0 -item "More items - $i"
- }
-
- display 2 "Deleting all items"
- VtListDeleteItem $lst -all
-
- VtListAddItem $lst -itemList {"first" "second" "third" "fourth" "last"}
-
- display 2 "Deleting first item..."
- VtListDeleteItem $lst -position 1
-
- display 2 "Restoring first item..."
- VtListAddItem $lst -position 1 -item "first"
-
- display 2 "Deleting last item..."
- VtListDeleteItem $lst -position 0
-
- display 2 "Restoring last item..."
- VtListAddItem $lst -position 0 -item "last"
-
- display 2 "Deleting item 3..."
- VtListDeleteItem $lst -position 3
-
- display 2 "Restoring item 3..."
- VtListAddItem $lst -position 3 -item "third"
-
- display 2 "Delete from 1 to 3"
- VtListDeleteItem $lst -positionList {1 2 3}
-
- display 2 "Restoring 1 to 3"
- VtListAddItem $lst -position 1 -itemList {first second third}
-
- display 2 "Deleteing by item name - second"
- VtListDeleteItem $lst -item second
-
- display 2 "Restoring "
- VtListAddItem $lst -position 2 -item "second"
-
- display 2 "Deleting by itemList - first second"
- VtListDeleteItem $lst -itemList {first second}
-
-
- display 2 "Testing -scrollBar"
- VtSetValues $lst -scrollBar 1
-
- display 2 "Done"
- }
-
- proc testSetCB {lst cbs} {
- display 1 "Testing VtListSetItem...."
-
- restoreList $lst
-
- display 2 " VtListSetItem by items ...."
- foreach i {first second third fourth fifth} {
- VtListSetItem $lst -item $i -newItem "New items $i"
- sleep 1
- }
-
- restoreList $lst
- display 2 " VtListSetItem by positions...."
- foreach i {1 2 3 4 5} {
- VtListSetItem $lst -position $i -newItem "New items $i"
- sleep 1
- }
-
- display 2 "Done"
- }
-
- proc testAllCB {lst cbs} {
- testAddCB $lst $cbs
- testSelectCB $lst $cbs
- testDSelectCB $lst $cbs
- testGetCB $lst $cbs
- testGetSelCB $lst $cbs
- testSetCB $lst $cbs
-
- display 0 "DONE !!"
- }
-
- proc mkCenteredBut {name label cb} {
-
- set pb [VtPushButton $name -label $label -callback $cb \
- -labelCenter]
-
- return pb
- }
-
- set ap [VtOpen "list"]
-
- set fn [VtStartForm $ap.form -title "List Tests"]
-
- set DisplayTxt [VtText $fn.txt \
- -columns 50 \
- -rows 2 \
- -wordWrap \
- -leftSide FORM -rightSide FORM -topSide FORM]
-
- set lst [VtList $fn.list \
- -itemList {"Initial one" "Initial two" "Initial three"} \
- -rows 6\
- -callback selectCB\
- -defaultCallback defaultCB\
- -leftSide FORM -rightSide FORM -topSide $DisplayTxt ]
-
- set rc [VtRowColumn $fn.rc -horizontal \
- -topSide NONE -bottomSide FORM -leftSide FORM \
- -packing COLUMN -numColumns 3]
-
- VtSetValues $lst -bottomSide $rc -topSide $DisplayTxt
-
- mkCenteredBut $rc.tstAll "Test All" "testAllCB $lst"
- mkCenteredBut $rc.tstAdd "Test Add" "testAddCB $lst"
- mkCenteredBut $rc.tstSel "Test Select" "testSelectCB $lst"
- mkCenteredBut $rc.tstGet "Test Get" "testGetCB $lst"
- mkCenteredBut $rc.tstDSel "Test DeSelect" "testDSelectCB $lst"
- mkCenteredBut $rc.tstGelS "Test Get Selected" "testGetSelCB $lst"
- mkCenteredBut $rc.tstSet "Test Set" "testSetCB $lst"
- mkCenteredBut $rc.tstTopI "Test TopItem" "testTopItemCB $lst"
- mkCenteredBut $rc.select "Select Style" "selectStyleCB $lst"
- mkCenteredBut $rc.quit "Exit" quitCB
-
-
- VtShowDialog $fn
-
- VtMainLoop
-