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