Modified display of GRS-1 records to include headings for standard
[ir-tcl-moved-to-github.git] / formats / line.tcl
1 # IR toolkit for tcl/tk
2 # (c) Index Data 1995
3 # See the file LICENSE for details.
4 # Sebastian Hammer, Adam Dickmeiss
5 #
6 # $Log: line.tcl,v $
7 # Revision 1.13  1996-04-12 12:25:27  adam
8 # Modified display of GRS-1 records to include headings for standard
9 # tag sets.
10 #
11 # Revision 1.12  1996/03/29  16:05:36  adam
12 # Bug fix: GRS records wasn't recognized.
13 #
14 # Revision 1.11  1996/01/23  15:24:21  adam
15 # Wrore more comments.
16 #
17 # Revision 1.10  1995/10/17  17:39:46  adam
18 # Minor bug fix in call to display-grs-line.
19 #
20 # Revision 1.9  1995/10/17  14:18:09  adam
21 # Minor changes in presentation formats.
22 #
23 # Revision 1.8  1995/10/17  10:58:08  adam
24 # More work on presentation formats.
25 #
26 # Revision 1.7  1995/09/20  11:37:06  adam
27 # Work on GRS.
28 #
29 # Revision 1.6  1995/06/29  12:34:20  adam
30 # IrTcl now works with both tk4.0b4/tcl7.4b4 and tk3.6/tcl7.3
31 #
32 # Revision 1.5  1995/06/22  13:16:28  adam
33 # Feature: SUTRS. Setting getSutrs implemented.
34 # Work on display formats.
35 #
36 # Revision 1.4  1995/06/19  08:10:21  adam
37 # Inverse highligt colours in monochrome mode.
38 #
39 # Revision 1.3  1995/06/16  12:29:00  adam
40 # Use insertWithTags on diagnostic errors.
41 #
42 # Revision 1.2  1995/06/13  14:39:06  adam
43 # Fix: if {$var != ""} doesn't work if var is a large numerical!
44 # Highlight when line format is used.
45 #
46 # Revision 1.1  1995/06/12  15:18:10  adam
47 # Work on presentation formats. These are used in the main window as well
48 # as popup windows.
49 #
50 #
51 proc display-grs-line {w r i} {
52     global tagSet
53     
54     if {[tk4]} {
55         set start [$w index insert]
56     }
57     foreach e $r {
58         if {![tk4]} {
59             for {set j 0} {$j < $i} {incr j} {
60                 insertWithTags $w "  " marc-tag
61             }
62         }
63         set ttype [lindex $e 0]
64         set tval [lindex $e 2]
65         if {[info exists tagSet($ttype,$tval)]} {
66             insertWithTags $w "$tagSet($ttype,$tval) " marc-pref
67         } else {
68             insertWithTags $w "$tval " marc-pref
69         }
70         if {[lindex $e 3] == "string"} {
71             insertWithTags $w [lindex $e 4] marc-text
72             insertWithTags $w "\n"
73             break
74         }
75     }
76     if {[tk4]} {
77         $w tag configure indent$i \
78                 -lmargin1 [expr $i * 10] \
79                 -lmargin2 [expr $i * 10 + 5]
80         $w tag add indent$i $start insert
81     }
82 }
83
84 # Procedure display-line {sno no w hflag}
85 #  sno    result set number (integer)
86 #  no     record position (integer)
87 #  w      text widget in which the record should be displayed.
88 #  hflag  header flag. If true a header showing the record position
89 #         should be displayed.
90 # This procedure attempts to display records in a line-per-line format.
91 proc display-line {sno no w hflag} {
92     global monoFlag
93     set type [z39.$sno type $no] 
94     if {$hflag} {
95         if {! $monoFlag} {
96             $w tag bind r$no <Any-Enter> \
97                 [list $w tag configure r$no -background gray80]
98             $w tag bind r$no <Any-Leave> \
99                 [list $w tag configure r$no -background {}]
100         } else {
101             $w tag bind r$no <Any-Enter> \
102                 [list $w tag configure r$no -background black -foreground white]
103             $w tag bind r$no <Any-Leave> \
104                 [list $w tag configure r$no -background {} -foreground {}]
105         }
106     } else {
107         $w delete 0.0 end
108     }
109     if {$hflag} {
110         set nostr [format "%5d " $no]
111         insertWithTags $w $nostr marc-small-head
112     }
113     if {$type == "DB"} {
114         set rtype [z39.$sno recordType $no]
115         if {$rtype == "SUTRS"} {
116             insertWithTags $w [join [z39.$sno getSutrs $no]]
117         } elseif {$rtype == "GRS-1"} {
118             display-grs-line $w [z39.$sno getGrs $no] 0
119         } else {
120             if {[catch {
121                 set title [lindex [z39.$sno getMarc $no field 245 * a] 0]
122                 set year  [lindex [z39.$sno getMarc $no field 260 * c] 0]
123                 insertWithTags $w "$title - " marc-text
124                 insertWithTags $w "$year\n" marc-it
125             }]} {
126                 insertWithTags $w "Unknown record type: $rtype\n" marc-id
127             }
128         }
129     } elseif {$type == "SD"} {
130         set err [lindex [z39.$sno diag $no] 1]
131         set add [lindex [z39.$sno diag $no] 2]
132         if {$add != {}} {
133             set add " :${add}"
134         }
135         insertWithTags $w "Error ${err}${add}\n" marc-id
136     } 
137 }