1# Copyright (c) 1994 by Sanjay Ghemawat
2#############################################################################
3
4# effects       Create scrollable text widget named "$w"
5#               The widget contains a text widget named "$w.text",
6#               and a scrollbar named "$w.scroll"
7proc make_scrolled_text {w} {
8    frame $w
9    scrollbar $w.scroll -orient vertical -command [list $w.text yview]
10    text $w.text -relief raised -borderwidth 1\
11        -yscrollcommand [list $w.scroll set]
12
13    pack $w.scroll -side right -fill y
14    pack $w.text -side left -expand 1 -fill both
15}
16
17set viewer_id 0
18
19# effects  Create text viewer and return its window name.
20#          The underlying text widget has name "<toplevel>.text"
21proc make_text_viewer {title iconname} {
22    global viewer_id
23    incr viewer_id
24    set f .textview$viewer_id
25
26    set t "$f.text"
27    set s "$f.scroll"
28
29    toplevel $f -class Viewer
30    wm iconname $f $iconname
31    wm title $f $title
32
33    # Move button to extreme right hand side.
34    # XXX This depends on the internals of "make_buttons".
35    make_buttons $f.bot 0 [list [list {Okay} [list destroy $f]]]
36    pack $f.bot.def0 -side right -expand 0
37
38    scrollbar $s -orient vertical -command [list $t yview]
39    text $t -setgrid 1 -yscroll "$s set" -height 25 -width 80
40    $t config -state disabled
41
42    pack $f.bot -side bottom -fill x
43    pack $s -side right -fill y
44    pack $t -side left -expand 1 -fill both
45
46    bind $f <Tab>               {break}
47    bind $f <Control-c>         {destroy %W}
48    bind $f <space>             {tkTextScrollPages %W.text 1}
49    bind $f <Control-f>         {tkTextScrollPages %W.text 1}
50    bind $f <Control-v>         {tkTextScrollPages %W.text 1}
51    bind $f <Control-b>         {tkTextScrollPages %W.text -1}
52    bind $f <Meta-v>            {tkTextScrollPages %W.text -1}
53    bind $f <Delete>            {tkTextScrollPages %W.text -1}
54    bind $f <BackSpace>         {tkTextScrollPages %W.text -1}
55
56    return $f
57}
58