OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itk/] [examples/] [TextDisplay.itk] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# ----------------------------------------------------------------------
2
#  EXAMPLE: TextDisplay widget
3
# ----------------------------------------------------------------------
4
#  COURSE:  Object-Oriented Programming with [incr Tcl]
5
#  AUTHOR:  Michael J. McLennan, Bell Labs Innovations
6
# ======================================================================
7
#               Copyright (c) 1996  Lucent Technologies
8
# ======================================================================
9
 
10
option add *TextDisplay.width 3i widgetDefault
11
option add *TextDisplay.height 2i widgetDefault
12
 
13
option add *TextDisplay.scrollbar auto widgetDefault
14
option add *TextDisplay.wrap none widgetDefault
15
option add *TextDisplay.textBackground ivory widgetDefault
16
 
17
class TextDisplay {
18
    inherit itk::Widget
19
 
20
    constructor {args} {
21
        itk_option add hull.width hull.height
22
 
23
        itk_component add text {
24
            text $itk_interior.info -state disabled -width 1 -height 1 \
25
                -yscrollcommand [code $itk_interior.sbar set]
26
        } {
27
            usual
28
            keep -wrap -tabs
29
            rename -background -textbackground textBackground Background
30
        }
31
        pack $itk_component(text) -side left -expand yes -fill both
32
 
33
        itk_component add scrollbar {
34
            scrollbar $itk_interior.sbar \
35
                -command [code $itk_interior.info yview]
36
        }
37
        pack $itk_component(scrollbar) -side right -fill y
38
 
39
        eval itk_initialize $args
40
 
41
        pack propagate $itk_component(hull) 0
42
 
43
        fixScrollbar
44
        bind $itk_component(text)  [code $this fixScrollbar]
45
 
46
        $itk_component(text) tag configure bold \
47
            -font -*-courier-bold-r-normal--*-120-*
48
 
49
        $itk_component(text) tag configure italic \
50
            -font -*-courier-medium-o-normal--*-120-*
51
    }
52
 
53
    public method display {info}
54
    public method append {info}
55
    public method substitute {word newword}
56
 
57
    itk_option define -scrollbar scrollbar Scrollbar "on" {
58
        switch -- $itk_option(-scrollbar) {
59
            on - off - auto {
60
                fixScrollbar
61
            }
62
            default {
63
                error "bad value \"$itk_option(-scollbar)\""
64
            }
65
        }
66
    }
67
 
68
    protected method fixScrollbar {}
69
    private variable sbvisible 1
70
}
71
 
72
body TextDisplay::display {args} {
73
    $itk_component(text) configure -state normal
74
    $itk_component(text) delete 1.0 end
75
    eval $itk_component(text) insert 1.0 $args
76
    $itk_component(text) configure -state disabled
77
    fixScrollbar
78
}
79
 
80
body TextDisplay::append {args} {
81
    $itk_component(text) configure -state normal
82
    eval $itk_component(text) insert end $args
83
    $itk_component(text) configure -state disabled
84
    fixScrollbar
85
}
86
 
87
body TextDisplay::substitute {word newword} {
88
    $itk_component(text) configure -state normal
89
 
90
    set index 1.0
91
    while {1} {
92
        set index [$itk_component(text) search -count len $word $index]
93
        if {$index != ""} {
94
            $itk_component(text) delete $index "$index + $len chars"
95
            $itk_component(text) insert $index $newword
96
        } else {
97
            break
98
        }
99
    }
100
    $itk_component(text) configure -state disabled
101
    fixScrollbar
102
}
103
 
104
body TextDisplay::fixScrollbar {} {
105
    switch $itk_option(-scrollbar) {
106
        on  { set sbstate 1 }
107
        off { set sbstate 0 }
108
 
109
        auto {
110
            if {[$itk_component(text) bbox 1.0] == "" ||
111
                [$itk_component(text) bbox end-1char] == ""} {
112
                set sbstate 1
113
            } else {
114
                set sbstate 0
115
            }
116
        }
117
    }
118
    if {$sbstate != $sbvisible} {
119
        if {$sbstate} {
120
            pack $itk_component(scrollbar) -side right -fill y
121
        } else {
122
            pack forget $itk_component(scrollbar)
123
        }
124
        set sbvisible $sbstate
125
    }
126
}
127
 
128
usual TextDisplay {
129
    keep -background -cursor -foreground -font
130
    keep -activebackground -activerelief
131
    keep -highlightcolor -highlightthickness
132
    keep -insertbackground -insertborderwidth -insertwidth
133
    keep -insertontime -insertofftime
134
    keep -selectbackground -selectborderwidth -selectforeground
135
    keep -textbackground -troughcolor
136
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.