OSDN Git Service

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