home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / languages / tcl / !wtest / texttest < prev    next >
Encoding:
Text File  |  1996-01-20  |  2.6 KB  |  107 lines

  1. # Test of the w_text document facilities
  2.  
  3. #create a paragraph to be written by "write"
  4. #include font change sequences |f<fontname>|
  5. #        colour change seqences |c<colourname>|
  6. #        vertical bars ||
  7. # you can see the unprocessed string by writing with processing off
  8.  
  9. set teststring "Some vertical bars:- ||||||||  "
  10. set cnames [array names colours]
  11. set fnames [array names fonts]
  12. foreach f $fnames\
  13.  { lappend teststring |f$f||cblack| $fonts($f)
  14.    foreach c $cnames\
  15.    { lappend teststring |c$c| $c
  16.    }
  17.  }
  18.  
  19. #set up some variables to hold the tick status of menu entries
  20. #set up trace procedures to call when they are changed 
  21.  
  22. set lmargin 1
  23. set rmargin 0
  24. set justify 0
  25. set process 0
  26. trace variable lmargin w setlmargin
  27. trace variable rmargin w setrmargin
  28. trace variable justify w setjustify
  29. trace variable process w setprocess
  30.  
  31.  
  32. #set the left margin using the -l<length> option
  33.  
  34. proc setlmargin {name element op}\
  35.  { global lmargin
  36.    w_text document options -l${lmargin}i
  37.  }
  38.  
  39.  
  40. #set the right margin with the -r<length> option
  41.  
  42. proc setrmargin {name element op}\
  43.  { global rmargin
  44.    w_text document options -r${rmargin}i
  45.  }
  46.  
  47.  
  48. #set whether to justify or not using -j0 or -j1
  49.  
  50. proc setjustify {name element op}\
  51.  { global justify
  52.    w_text document options -j$justify
  53.  }
  54.  
  55.  
  56. #set whether to process || sequences using -p0 or -p1
  57.  
  58. proc setprocess {name element op}\
  59.  { global process
  60.    w_text document options -p$process
  61.  }
  62.  
  63.  
  64. #data for the menu
  65. #excercises print and write commands
  66. #and the -L -R and -C options for print
  67.  
  68. set docmenu\
  69.  { Document
  70.    {Print -click {w_text document print "Hello World"}}
  71.    {Write -click {w_text document write $teststring}}
  72.    {Left -click {w_text document options -L}}
  73.    {Center -click {w_text document options -C}}
  74.    {Right -click {w_text document options -R}}
  75.    {LMargin -tick lmargin}
  76.    {RMargin -tick rmargin}
  77.    {Justfy -tick justify}
  78.    {Process -tick process}
  79.  }
  80.  
  81.  
  82. #Create a text document called "document"
  83. #It has title "A text window"
  84. #If you close a window on it it the script "expr 2" will be run, as this
  85. # returns 2 the window will be closed but the document will still exist.
  86. #As yet there is no text in the window.
  87.  
  88. w_text document create -title "A text window"\
  89.                        -fg black\
  90.                        -bg white\
  91.                        -width 6i\
  92.                        -height 30p\
  93.                        -size 20p\
  94.                        -close {expr 2}\
  95.                        -menu $docmenu
  96.  
  97.  
  98. #start with a 1 inch left margin
  99.  
  100. w_text document options -l${lmargin}i
  101.  
  102. #open a window on " document"
  103. #you can open several windows but the all show the same document.
  104.  
  105. proc textopen {}\
  106.  { w_text document open
  107.  }