1# style.tcl --
2#
3# This demonstration script creates a text widget that illustrates the
4# various display styles that may be set for tags.
5#
6# RCS: @(#) $Id$
7
8if {![info exists widgetDemo]} {
9    error "This script should be run from the \"widget\" demo."
10}
11
12package require Tk
13
14set w .style
15catch {destroy $w}
16toplevel $w
17wm title $w "Text Demonstration - Display Styles"
18wm iconname $w "style"
19positionWindow $w
20
21## See Code / Dismiss buttons
22set btns [addSeeDismiss $w.buttons $w]
23pack $btns -side bottom -fill x
24
25# Only set the font family in one place for simplicity and consistency
26
27set family Courier
28
29text $w.text -yscrollcommand "$w.scroll set" -setgrid true \
30	-width 70 -height 32 -wrap word -font "$family 12"
31scrollbar $w.scroll -command "$w.text yview"
32pack $w.scroll -side right -fill y
33pack $w.text -expand yes -fill both
34
35# Set up display styles
36
37$w.text tag configure bold -font "$family 12 bold italic"
38$w.text tag configure big -font "$family 14 bold"
39$w.text tag configure verybig -font "Helvetica 24 bold"
40$w.text tag configure tiny -font "Times 8 bold"
41if {[winfo depth $w] > 1} {
42    $w.text tag configure color1 -background #a0b7ce
43    $w.text tag configure color2 -foreground red
44    $w.text tag configure raised -relief raised -borderwidth 1
45    $w.text tag configure sunken -relief sunken -borderwidth 1
46} else {
47    $w.text tag configure color1 -background black -foreground white
48    $w.text tag configure color2 -background black -foreground white
49    $w.text tag configure raised -background white -relief raised \
50	    -borderwidth 1
51    $w.text tag configure sunken -background white -relief sunken \
52	    -borderwidth 1
53}
54$w.text tag configure bgstipple -background black -borderwidth 0 \
55	-bgstipple gray12
56$w.text tag configure fgstipple -fgstipple gray50
57$w.text tag configure underline -underline on
58$w.text tag configure overstrike -overstrike on
59$w.text tag configure right -justify right
60$w.text tag configure center -justify center
61$w.text tag configure super -offset 4p -font "$family 10"
62$w.text tag configure sub -offset -2p -font "$family 10"
63$w.text tag configure margins -lmargin1 12m -lmargin2 6m -rmargin 10m
64$w.text tag configure spacing -spacing1 10p -spacing2 2p \
65	-lmargin1 12m -lmargin2 6m -rmargin 10m
66
67$w.text insert end {Text widgets like this one allow you to display information in a
68variety of styles.  Display styles are controlled using a mechanism
69called }
70$w.text insert end tags bold
71$w.text insert end {.  Tags are just textual names that you can apply to one
72or more ranges of characters within a text widget.  You can configure
73tags with various display styles.  If you do this, then the tagged
74characters will be displayed with the styles you chose.  The
75available display styles are:
76}
77$w.text insert end "\n1. Font." big
78$w.text insert end "  You can choose any system font, "
79$w.text insert end large verybig
80$w.text insert end " or "
81$w.text insert end "small" tiny ".\n"
82$w.text insert end "\n2. Color." big
83$w.text insert end "  You can change either the "
84$w.text insert end background color1
85$w.text insert end " or "
86$w.text insert end foreground color2
87$w.text insert end "\ncolor, or "
88$w.text insert end both {color1 color2}
89$w.text insert end ".\n"
90$w.text insert end "\n3. Stippling." big
91$w.text insert end "  You can cause either the "
92$w.text insert end background bgstipple
93$w.text insert end " or "
94$w.text insert end foreground fgstipple
95$w.text insert end {
96information to be drawn with a stipple fill instead of a solid fill.
97}
98$w.text insert end "\n4. Underlining." big
99$w.text insert end "  You can "
100$w.text insert end underline underline
101$w.text insert end " ranges of text.\n"
102$w.text insert end "\n5. Overstrikes." big
103$w.text insert end "  You can "
104$w.text insert end "draw lines through" overstrike
105$w.text insert end " ranges of text.\n"
106$w.text insert end "\n6. 3-D effects." big
107$w.text insert end {  You can arrange for the background to be drawn
108with a border that makes characters appear either }
109$w.text insert end raised raised
110$w.text insert end " or "
111$w.text insert end sunken sunken
112$w.text insert end ".\n"
113$w.text insert end "\n7. Justification." big
114$w.text insert end " You can arrange for lines to be displayed\n"
115$w.text insert end "left-justified,\n"
116$w.text insert end "right-justified, or\n" right
117$w.text insert end "centered.\n" center
118$w.text insert end "\n8. Superscripts and subscripts."  big
119$w.text insert end " You can control the vertical\n"
120$w.text insert end "position of text to generate superscript effects like 10"
121$w.text insert end "n" super
122$w.text insert end " or\nsubscript effects like X"
123$w.text insert end "i" sub
124$w.text insert end ".\n"
125$w.text insert end "\n9. Margins." big
126$w.text insert end " You can control the amount of extra space left"
127$w.text insert end " on\neach side of the text:\n"
128$w.text insert end "This paragraph is an example of the use of " margins
129$w.text insert end "margins.  It consists of a single line of text " margins
130$w.text insert end "that wraps around on the screen.  There are two " margins
131$w.text insert end "separate left margin values, one for the first " margins
132$w.text insert end "display line associated with the text line, " margins
133$w.text insert end "and one for the subsequent display lines, which " margins
134$w.text insert end "occur because of wrapping.  There is also a " margins
135$w.text insert end "separate specification for the right margin, " margins
136$w.text insert end "which is used to choose wrap points for lines.\n" margins
137$w.text insert end "\n10. Spacing." big
138$w.text insert end " You can control the spacing of lines with three\n"
139$w.text insert end "separate parameters.  \"Spacing1\" tells how much "
140$w.text insert end "extra space to leave\nabove a line, \"spacing3\" "
141$w.text insert end "tells how much space to leave below a line,\nand "
142$w.text insert end "if a text line wraps, \"spacing2\" tells how much "
143$w.text insert end "space to leave\nbetween the display lines that "
144$w.text insert end "make up the text line.\n"
145$w.text insert end "These indented paragraphs illustrate how spacing " spacing
146$w.text insert end "can be used.  Each paragraph is actually a " spacing
147$w.text insert end "single line in the text widget, which is " spacing
148$w.text insert end "word-wrapped by the widget.\n" spacing
149$w.text insert end "Spacing1 is set to 10 points for this text, " spacing
150$w.text insert end "which results in relatively large gaps between " spacing
151$w.text insert end "the paragraphs.  Spacing2 is set to 2 points, " spacing
152$w.text insert end "which results in just a bit of extra space " spacing
153$w.text insert end "within a pararaph.  Spacing3 isn't used " spacing
154$w.text insert end "in this example.\n" spacing
155$w.text insert end "To see where the space is, select ranges of " spacing
156$w.text insert end "text within these paragraphs.  The selection " spacing
157$w.text insert end "highlight will cover the extra space." spacing
158