home *** CD-ROM | disk | FTP | other *** search
-
-
- # just ignore this file for before Motif 2.0
- if {$XmVersion >= 2000} {
-
- if {[string compare test [info procs test]] == 1} then \
- {source defs}
-
- # set VERBOSE 1
- # set INTERACTIVE 1
-
- proc no-changeCB {doit} {
- upvar 1 $doit d
-
- set d false
- }
-
- proc allcaps {text} {
- upvar 1 $text p
-
- set upper [string toupper $p]
- set p $upper
- }
-
-
- #############
- # starts here
- #############
-
- xtAppInitialize -class Text
- . setValues -allowShellResize true
-
- # XtText does not have a natural size, but doesn't like
- # zero width, so let a label set a >0 width
- xmRowColumn .rc managed
- xmLabel .rc.label managed
-
- xmCSText .rc.text managed \
- -columns 40
- . realizeWidget
-
- ##################################
- # Manipulating text by resources #
- ##################################
-
- test text-1.1 {setting and getting text} {
- .rc.text setValues -cstextValue "The rain in Spain"
- .rc.text getValues -cstextValue v
- set v
- } {The rain in Spain}
-
- ################################
- # Manipulating text by actions #
- ################################
-
- test text-2.1 {appending text by insert-string} {
- .rc.text callActionProc end-of-file()
- .rc.text callActionProc {insert-string(" falls mainly")}
- .rc.text getValues -cstextValue v
- set v
- } {The rain in Spain falls mainly}
-
- test text-2.2 {deleting text by delete-previous-character} {
- .rc.text callActionProc delete-previous-character()
- .rc.text callActionProc delete-previous-character()
- .rc.text getValues -cstextValue v
- set v
- } {The rain in Spain falls main}
-
- test test-2.3 {inserting text by self-insert} {
- .rc.text setValues -cstextValue ""
- .rc.text callActionProc self-insert() \
- -type KeyPress \
- -keysym T
- .rc.text callActionProc self-insert() \
- -type KeyPress \
- -keysym h
- .rc.text callActionProc self-insert() \
- -type KeyPress \
- -keysym space
- .rc.text callActionProc self-insert() \
- -type KeyPress \
- -keysym 9
- .rc.text getValues -cstextValue v
- set v
- } {Th 9}
-
- #############################
- # modification verification #
- #############################
-
- ############
- # no changes
- ############
- test text-3.1 {turn off every change in modifyVerify callback} {
- .rc.text setValues -cstextValue "The rain in Spain"
-
- .rc.text modifyVerifyCallback {no-changeCB %doit}
-
- .rc.text callActionProc {insert-string(" falls mainly")}
- .rc.text getValues -cstextValue v
- set v
- } {The rain in Spain}
-
- ####################
- # capitalize changes
- ####################
- .rc.text destroyWidget
- xmCSText .rc.text managed \
- -columns 40
-
- test text-3.2 {change text in modifyVerify callback} {
- .rc.text setValues -cstextValue "The rain in Spain"
- .rc.text callActionProc end-of-file()
-
- .rc.text modifyVerifyCallback {allcaps %text}
-
- .rc.text callActionProc {insert-string(" FalLs mAInlY")}
- .rc.text getValues -cstextValue v
- set v
- } {The rain in Spain FALLS MAINLY}
-
- #####################################
- # setting and getting text by methods
- #####################################
-
- .rc.text destroyWidget
- puts stdout destroyed
- xmCSText .rc.text managed \
- -columns 40
-
- test text-4.1 {set and get text} {
- .rc.text setString "hello world"
- .rc.text getString
- } {hello world}
-
- if {$XmVersion >= 1002} {
- test text-4.2 {get a substring} {
- set found [.rc.text getSubstring 2 3 value]
- if {$found == "succeeded"} {
- set result $value
- } else {set result $found}
- set result
- } {llo}
- }
-
- ####################################
- # getting and setting editable state
- ####################################
-
- test text-5.1 {set and get editable state} {
- .rc.text setEditable false
- .rc.text getEditable
- } {false}
-
- test text-5.2 {set and get editable state} {
- .rc.text setEditable true
- .rc.text getEditable
- } {true}
-
- ########################################
- # getting and setting insertion position
- ########################################
-
- test text-6.1 {getting and setting insertion position} {
- .rc.text setInsertionPosition 5
- .rc.text getInsertionPosition
- } {5}
-
- test text-6.2 {getting last position} {
- .rc.text setString "hello porkpie hat"
- .rc.text getLastPosition
- } {17}
-
- #################
- # finding strings
- #################
-
- .rc.text setString "hello world"
-
- if {$XmVersion >= 1002} {
- test text-7.1 {search forward for string} {
- .rc.text findString 1 wor forward position
- set position
- } {6}
-
- test text-7.2 {search backward for string} {
- .rc.text findString 10 wor backward position
- set position
- } {6}
-
- test text-7.3 {search for non-existent string} {
- .rc.text findString 1 universe forward position
- } {false}
- }
-
- ############################
- # manipulating parts of text
- ############################
-
- test text-8.1 {insert text} {
- .rc.text setString "abcdefgh"
- .rc.text insert 3 PQRST
- .rc.text getString
- } {abcPQRSTdefgh}
-
- test text-8.2 {replace text} {
- .rc.text replace 3 8 IJKL
- .rc.text getString
- } {abcIJKLdefgh}
-
- #########################
- # scroll and top position
- #########################
-
- test text-9.1 {scroll and top position} {
- .rc.text setValues -editMode multi_line_edit
- .rc.text setString "one @n two @n three"
- .rc.text scroll 2
- .rc.text getTopCharacter
- } {8}
-
- test text-9.2 {set top character} {
- .rc.text setTopCharacter 5
- .rc.text getTopCharacter
- } {4}
-
- test text-9.3 {show position} {
- .rc.text setValues -autoShowCursorPosition true
- .rc.text showPosition 2
- .rc.text getInsertionPosition
- } {0}
-
- ##################
- # multiple sources
- ##################
-
- test text-10.1 {two sources} {
- .rc.text destroyWidget
- xmRowColumn .rc.rc managed
- xmCSText .rc.rc.text managed
- xmCSText .rc.rc.text2 managed
- .rc.rc.text setString abcdefgh
- .rc.rc.text2 setSource .rc.rc.text 0 0
- .rc.rc.text2 getString
- } {abcdefgh}
-
- .rc.rc destroyWidget
-
-
- ###################
- # primary selection
- ###################
-
- xmCSText .rc.text managed
-
- test text-11.1 {managing the primary selection} {
- .rc.text setString "hello world"
- .rc.text setSelection 2 7
- .rc.text getSelection
- } {llo w}
-
- test text-11.2 {locating primary selection} {
- .rc.text getSelectionPosition left right
- set result "$left $right"
- set result
- } {2 7}
-
- test text-11.3 {copy and paste primary selection} {
- .rc.text copy
- .rc.text setInsertionPosition 1
- .rc.text paste
- .rc.text getString
- } {hllo wello world}
-
- test text-11.4 {cut and paste the primary selection} {
- .rc.text setString "hello world"
- .rc.text setSelection 2 7
- .rc.text cut
- .rc.text setInsertionPosition 0
- .rc.text paste
- .rc.text getString
- } {llo wheorld}
-
-
- #############
- # Finish up #
- #############
- if { ! $INTERACTIVE} {
- .rc.label destroyWidget
- .rc.text destroyWidget
- .rc destroyWidget
- } else {
- . mainLoop
- }
-
- }
-