~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to gcl-tk/demos/mkStyles.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# mkStyles w
 
2
#
 
3
# Create a top-level window with a text widget that demonstrates the
 
4
# various display styles that are available in texts.
 
5
#
 
6
# Arguments:
 
7
#    w -        Name to use for new top-level window.
 
8
 
 
9
proc mkStyles {{w .styles}} {
 
10
    catch {destroy $w}
 
11
    toplevel $w
 
12
    dpos $w
 
13
    wm title $w "Text Demonstration - Display Styles"
 
14
    wm iconname $w "Text Styles"
 
15
 
 
16
    button $w.ok -text OK -command "destroy $w"
 
17
    text $w.t -relief raised -bd 2 -yscrollcommand "$w.s set" -setgrid true \
 
18
            -width 70 -height 28
 
19
    scrollbar $w.s -relief flat -command "$w.t yview"
 
20
    pack $w.ok -side bottom -fill x
 
21
    pack $w.s -side right -fill y
 
22
    pack $w.t -expand yes -fill both
 
23
 
 
24
    # Set up display styles
 
25
 
 
26
    $w.t tag configure bold -font -Adobe-Courier-Bold-O-Normal-*-120-*
 
27
    $w.t tag configure big -font -Adobe-Courier-Bold-R-Normal-*-140-*
 
28
    $w.t tag configure verybig -font -Adobe-Helvetica-Bold-R-Normal-*-240-*
 
29
    if {[tk colormodel $w] == "color"} {
 
30
        $w.t tag configure color1 -background #eed5b7
 
31
        $w.t tag configure color2 -foreground red
 
32
        $w.t tag configure raised -background #eed5b7 -relief raised \
 
33
                -borderwidth 1
 
34
        $w.t tag configure sunken -background #eed5b7 -relief sunken \
 
35
                -borderwidth 1
 
36
    } else {
 
37
        $w.t tag configure color1 -background black -foreground white
 
38
        $w.t tag configure color2 -background black -foreground white
 
39
        $w.t tag configure raised -background white -relief raised \
 
40
                -borderwidth 1
 
41
        $w.t tag configure sunken -background white -relief sunken \
 
42
                -borderwidth 1
 
43
    }
 
44
    $w.t tag configure bgstipple -background black -borderwidth 0 \
 
45
            -bgstipple gray25
 
46
    $w.t tag configure fgstipple -fgstipple gray50
 
47
    $w.t tag configure underline -underline on
 
48
 
 
49
    $w.t insert 0.0 {\
 
50
Text widgets like this one allow you to display information in a
 
51
variety of styles.  Display styles are controlled using a mechanism
 
52
called }
 
53
    insertWithTags $w.t tags bold
 
54
    insertWithTags $w.t {. Tags are just textual names that you can apply to one
 
55
or more ranges of characters within a text widget.  You can configure
 
56
tags with various display styles.  If you do this, then the tagged
 
57
characters will be displayed with the styles you chose.  The
 
58
available display styles are:
 
59
}
 
60
    insertWithTags $w.t {
 
61
1. Font.} big
 
62
    insertWithTags $w.t {  You can choose any X font, }
 
63
    insertWithTags $w.t large verybig
 
64
    insertWithTags $w.t { or }
 
65
    insertWithTags $w.t {small.
 
66
}
 
67
    insertWithTags $w.t {
 
68
2. Color.} big
 
69
    insertWithTags $w.t {  You can change either the }
 
70
    insertWithTags $w.t background color1
 
71
    insertWithTags $w.t { or }
 
72
    insertWithTags $w.t foreground color2
 
73
    insertWithTags $w.t {
 
74
color, or }
 
75
    insertWithTags $w.t both color1 color2
 
76
    insertWithTags $w.t {.
 
77
}
 
78
    insertWithTags $w.t {
 
79
3. Stippling.} big
 
80
    insertWithTags $w.t {  You can cause either the }
 
81
    insertWithTags $w.t background bgstipple
 
82
    insertWithTags $w.t { or }
 
83
    insertWithTags $w.t foreground fgstipple
 
84
    insertWithTags $w.t {
 
85
information to be drawn with a stipple fill instead of a solid fill.
 
86
}
 
87
    insertWithTags $w.t {
 
88
4. Underlining.} big
 
89
    insertWithTags $w.t {  You can }
 
90
    insertWithTags $w.t underline underline
 
91
    insertWithTags $w.t { ranges of text.
 
92
}
 
93
    insertWithTags $w.t {
 
94
5. 3-D effects.} big
 
95
    insertWithTags $w.t {  You can arrange for the background to be drawn
 
96
with a border that makes characters appear either }
 
97
    insertWithTags $w.t raised raised
 
98
    insertWithTags $w.t { or }
 
99
    insertWithTags $w.t sunken sunken
 
100
    insertWithTags $w.t {.
 
101
}
 
102
    insertWithTags $w.t {
 
103
6. Yet to come.} big
 
104
    insertWithTags $w.t {  More display effects will be coming soon, such
 
105
as the ability to change line justification and perhaps line spacing.}
 
106
 
 
107
    $w.t mark set insert 0.0
 
108
    bind $w <Any-Enter> "focus $w.t"
 
109
}
 
110
 
 
111
# The procedure below inserts text into a given text widget and
 
112
# applies one or more tags to that text.  The arguments are:
 
113
#
 
114
# w             Window in which to insert
 
115
# text          Text to insert (it's inserted at the "insert" mark)
 
116
# args          One or more tags to apply to text.  If this is empty
 
117
#               then all tags are removed from the text.
 
118
 
 
119
proc insertWithTags {w text args} {
 
120
    set start [$w index insert]
 
121
    $w insert insert $text
 
122
    foreach tag [$w tag names $start] {
 
123
        $w tag remove $tag $start insert
 
124
    }
 
125
    foreach i $args {
 
126
        $w tag add $i $start insert
 
127
    }
 
128
}