1 /*   e2docsum.c
2 * ===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *            National Center for Biotechnology Information (NCBI)
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government do not place any restriction on its use or reproduction.
13 *  We would, however, appreciate having the NCBI and the author cited in
14 *  any work or product based on this material
15 *
16 *  Although all reasonable efforts have been taken to ensure the accuracy
17 *  and reliability of the software and data, the NLM and the U.S.
18 *  Government do not and cannot warrant the performance or results that
19 *  may be obtained by using this software or data. The NLM and the U.S.
20 *  Government disclaim all warranties, express or implied, including
21 *  warranties of performance, merchantability or fitness for any particular
22 *  purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name:  e2docsum.c
27 *
28 * Author:  Jonathan Kans, Greg Schuler, Jonathan Epstein, Tim Ford
29 *
30 * Version Creation Date:   10/30/01
31 *
32 * $Revision: 6.58 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 *
39 * ==========================================================================
40 */
41 
42 #include <objmgr.h>
43 #include <asn2gnbk.h>
44 #include <explore.h>
45 #include <tomedlin.h>
46 #include <tofasta.h>
47 #include <simple.h>
48 #include <objproj.h>
49 #include <mmdbapi.h>
50 #include <blast.h>
51 #include <blastpri.h>
52 #include <simutil.h>
53 #include <bspview.h>
54 #include <medview.h>
55 #include <vibrant.h>
56 #include <document.h>
57 #include <asn.h>
58 #include <ent2api.h>
59 #include <urlquery.h>
60 #include <dlogutil.h>
61 #include <pmfapi.h>
62 #include <strucapi.h>
63 #include <mimapi.h>
64 #include <objmime.h>
65 #include <cn3dopen.h>
66 
67 #include <entrez2.h>
68 
69 #define MAX_DBS            64
70 #define MAX_UIDS           30000
71 #define DocUid             Int4
72 #define WORST_ID_BUFF_SIZE 256
73 
74 #define FETCH_MODE         1
75 #define EVAL_MODE          2
76 
77 #define NO_AUTHOR_STR      "[No Author Available]"
78 #define NO_TITLE_STR       "[No Title Available]"
79 #define NO_SOURCE_STR      "[No Source Available]"
80 #define NO_DATE_STR        "[No Date Available]"
81 #define NO_VOLUME_STR      "[No Volume Available]"
82 #define NO_PAGE_STR        "[No Page Available]"
83 #define NO_CAPTION_STR     "[No Caption Available]"
84 #define NO_UID_STR         "[No UID Available]"
85 
86 /*----------------------*/
87 /* Set up static arrays */
88 /*----------------------*/
89 
90 static ParData  docsumParFmt = { TRUE, FALSE, FALSE, FALSE, FALSE, 0, 0 };
91 static ColData  docsumColFmt [] = {
92   {0, 0, 15, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, FALSE},   /* caption  */
93   {0, 5, 65, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, TRUE}     /* term     */
94 };
95 static ColData  textColFmt [] = {
96   {0, 0, 80, 0, NULL, 'l', FALSE, FALSE, FALSE, FALSE, TRUE}    /* text     */
97 };
98 
99 /*--------------*/
100 /* Define icons */
101 /*--------------*/
102 
103 static Uint1  hasabstract [] = {
104   0x07, 0xF8, 0x1F, 0xE0, 0x78, 0x07, 0xE0, 0x1E,
105   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
106   0x40, 0x01, 0x80, 0x02, 0x4F, 0xF9, 0x9F, 0xF2,
107   0x40, 0x01, 0x80, 0x02, 0x4F, 0xF9, 0x9F, 0xF2,
108   0x40, 0x01, 0x80, 0x02, 0x4F, 0xF9, 0x9F, 0xF2,
109   0x40, 0x01, 0x80, 0x02, 0x4F, 0xF9, 0x9F, 0xF2,
110   0x40, 0x01, 0x80, 0x02, 0x4F, 0xF9, 0x9F, 0xF2,
111   0x40, 0x01, 0x80, 0x02, 0x4F, 0xF9, 0x9F, 0xF2,
112   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
113   0x40, 0x01, 0x80, 0x02, 0x47, 0xF9, 0x9F, 0xE2,
114   0x7F, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFE
115 };
116 
117 static Uint1  noabstract [] = {
118   0x07, 0xF8, 0x1F, 0xE0, 0x78, 0x07, 0xE0, 0x1E,
119   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
120   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
121   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
122   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
123   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
124   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
125   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
126   0x40, 0x01, 0x80, 0x02, 0x40, 0x01, 0x80, 0x02,
127   0x40, 0x01, 0x80, 0x02, 0x47, 0xF9, 0x9F, 0xE2,
128   0x7F, 0xFF, 0xFF, 0xFE, 0x7F, 0xFF, 0xFF, 0xFE
129 };
130 
131 static Uint1  proteinicon [] = {
132   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
133   0x40, 0x00, 0x00, 0x02, 0x43, 0x83, 0x80, 0x02,
134   0x44, 0x44, 0x40, 0x02, 0x43, 0xC3, 0xC0, 0x02,
135   0x44, 0x44, 0x40, 0x02, 0x44, 0x44, 0x40, 0x02,
136   0x44, 0x44, 0x40, 0x02, 0x43, 0xE3, 0xE0, 0x02,
137   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
138   0x40, 0x00, 0x00, 0x02, 0x47, 0xE7, 0xE7, 0xE2,
139   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
140   0x47, 0xE7, 0xE7, 0xE2, 0x40, 0x00, 0x00, 0x02,
141   0x40, 0x00, 0x00, 0x02, 0x47, 0xE7, 0xE7, 0xE2,
142   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
143 };
144 
145 static Uint1  dnaicon [] = {
146   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
147   0x40, 0x00, 0x00, 0x02, 0x45, 0x81, 0x00, 0x02,
148   0x46, 0x41, 0x00, 0x02, 0x44, 0x47, 0xC0, 0x02,
149   0x44, 0x41, 0x00, 0x02, 0x44, 0x41, 0x00, 0x02,
150   0x44, 0x41, 0x00, 0x02, 0x44, 0x60, 0xC0, 0x02,
151   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
152   0x40, 0x00, 0x00, 0x02, 0x4F, 0x7B, 0xDE, 0xF2,
153   0x40, 0x00, 0x00, 0x02, 0x4F, 0x7B, 0xDE, 0xF2,
154   0x40, 0x00, 0x00, 0x02, 0x4F, 0x7B, 0xDE, 0xF2,
155   0x40, 0x00, 0x00, 0x02, 0x4F, 0x7B, 0xDE, 0xF2,
156   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
157 };
158 
159 static Uint1  threedicon [] = {
160   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
161   0x40, 0x00, 0x00, 0x02, 0x4E, 0x0E, 0x00, 0x02,
162   0x41, 0x09, 0x00, 0x02, 0x40, 0x88, 0x80, 0x02,
163   0x47, 0x08, 0x80, 0x02, 0x40, 0x88, 0x80, 0x02,
164   0x41, 0x09, 0x00, 0x02, 0x4E, 0x0E, 0x00, 0x02,
165   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
166   0x40, 0x00, 0x00, 0x02, 0x47, 0xE0, 0x00, 0x02,
167   0x40, 0x07, 0xE0, 0x02, 0x40, 0x00, 0x07, 0xE2,
168   0x47, 0xE0, 0x00, 0x02, 0x40, 0x07, 0xE0, 0x02,
169   0x40, 0x00, 0x07, 0xE2, 0x47, 0xE0, 0x00, 0x02,
170   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
171 };
172 
173 static Uint1  genomeicon [] = {
174   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
175   0x40, 0xF0, 0xF0, 0x02, 0x41, 0x01, 0x08, 0x02,
176   0x41, 0x01, 0x00, 0x02, 0x41, 0x01, 0x00, 0x02,
177   0x41, 0x01, 0x38, 0x02, 0x41, 0x01, 0x10, 0x02,
178   0x40, 0xF0, 0xE0, 0x02, 0x40, 0x00, 0x00, 0x02,
179 #ifdef USE_CHROMOSOME_BANDS_IN_ICON
180 /* chromosome bands */
181   0x40, 0x00, 0x00, 0x02, 0x4F, 0xEF, 0xFF, 0xF2,
182   0x50, 0x10, 0xC4, 0xEA, 0x50, 0x10, 0xC4, 0xEA,
183   0x50, 0x10, 0xC4, 0xEA, 0x50, 0x10, 0xC4, 0xEA,
184   0x50, 0x10, 0xC4, 0xEA, 0x50, 0x10, 0xC4, 0xEA,
185   0x50, 0x10, 0xC4, 0xEA, 0x4F, 0xEF, 0xFF, 0xF2,
186   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
187 #else
188 /* show alignment */
189   0x40, 0x00, 0x00, 0x02, 0x4F, 0xFF, 0xFF, 0xF2,
190   0x48, 0x00, 0x00, 0x12, 0x4F, 0xFF, 0xFF, 0xF2,
191   0x40, 0x00, 0x00, 0x02, 0x40, 0xE0, 0xFF, 0x02,
192   0x40, 0x00, 0x00, 0x02, 0x4F, 0x0F, 0x80, 0x02,
193   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
194   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
195 #endif
196 };
197 
198 static Uint1  popseticon [] = {
199   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
200   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
201   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
202   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
203   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
204   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
205   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
206   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
207   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
208   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
209   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
210 };
211 
212 static Uint1  omimicon [] = {
213   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
214   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
215   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
216   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
217   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
218   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
219   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
220   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
221   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
222   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
223   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
224 };
225 
226 static Uint1  taxonomyicon [] = {
227   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
228   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
229   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
230   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
231   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
232   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
233   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
234   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
235   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
236   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
237   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
238 };
239 
240 static Uint1  booksicon [] = {
241   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
242   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
243   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
244   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
245   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
246   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
247   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
248   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
249   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
250   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
251   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
252 };
253 
254 static Uint1  probeicon [] = {
255   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
256   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
257   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
258   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
259   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
260   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
261   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
262   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
263   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
264   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
265   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
266 };
267 
268 static Uint1  domainicon [] = {
269   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
270   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
271   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
272   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
273   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
274   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
275   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
276   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
277   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
278   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
279   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
280 };
281 
282 static Uint1  stsicon [] = {
283   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
284   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
285   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
286   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
287   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
288   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
289   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
290   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
291   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
292   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
293   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
294 };
295 
296 static Uint1  cddicon [] = {
297   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
298   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
299   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
300   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
301   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
302   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
303   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
304   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
305   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
306   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
307   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
308 };
309 
310 static Uint1  snpicon [] = {
311   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
312   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
313   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
314   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
315   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
316   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
317   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
318   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
319   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
320   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
321   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
322 };
323 
324 static Uint1  journalsicon [] = {
325   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
326   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
327   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
328   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
329   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
330   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
331   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
332   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
333   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
334   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
335   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
336 };
337 
338 static Uint1  unigeneicon [] = {
339   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
340   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
341   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
342   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
343   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
344   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
345   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
346   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
347   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
348   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
349   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
350 };
351 
352 static Uint1  pmcicon [] = {
353   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
354   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
355   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
356   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
357   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
358   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
359   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
360   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
361   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
362   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
363   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
364 };
365 
366 static Uint1  ncbisearchicon [] = {
367   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
368   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
369   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
370   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
371   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
372   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
373   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
374   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
375   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
376   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
377   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
378 };
379 
380 static Uint1  meshicon [] = {
381   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
382   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
383   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
384   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
385   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
386   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
387   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
388   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
389   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
390   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
391   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
392 };
393 
394 static Uint1  geneicon [] = {
395   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
396   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
397   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
398   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
399   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
400   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
401   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
402   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
403   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
404   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
405   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
406 };
407 
408 static Uint1  genericon [] = {
409   0x7F, 0xFF, 0xFF, 0xFE, 0x40, 0x00, 0x00, 0x02,
410   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
411   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
412   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
413   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
414   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
415   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
416   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
417   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
418   0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02,
419   0x40, 0x00, 0x00, 0x02, 0x7F, 0xFF, 0xFF, 0xFE
420 };
421 
422 /*-----------------------------------------*/
423 /* Define the possible documents types for */
424 /* each database and the functions used to */
425 /* retrieve these documents.               */
426 /*-----------------------------------------*/
427 
428 static CharPtr  defaultRadios [] = { "Summary", "Fields", "Unique ID", NULL };
429 static CharPtr  medRadios [] = { "Summary", "Fields", "Abstract", "Citation", "MEDLINE", "PubMed ID", NULL };
430 static CharPtr  prtRadios [] = { "Summary", "Fields", "GenPept", "FASTA", "Protein ID", NULL };
431 static CharPtr  nucRadios [] = { "Summary", "Fields", "GenBank", "EMBL", "FASTA", "CDS FASTA", "Nucleotide ID", NULL };
432 static CharPtr  strucRadios [] = { "Summary", "Fields", "Report", "Structure ID", NULL };
433 static CharPtr  genRadios [] = { "Summary", "Fields", "Genome ID", NULL };
434 static CharPtr  popsetRadios [] = { "Summary", "Fields", "Sequence ID", NULL };
435 static CharPtr  omimRadios [] = { "Summary", "Fields", "MIM ID", NULL };
436 static CharPtr  taxonomyRadios [] = { "Summary", "Fields", "Taxon ID", NULL };
437 static CharPtr  bookRadios [] = { "Summary", "Fields", "Book ID", NULL };
438 static CharPtr  probeRadios [] = { "Summary", "Fields", "ProbeSet ID", NULL };
439 static CharPtr  domainRadios [] = { "Summary", "Fields", "3D Domain ID", NULL };
440 static CharPtr  stsRadios [] = { "Summary", "Fields", "UniSTS ID", NULL };
441 static CharPtr  cddRadios [] = { "Summary", "Fields", "Conserved Domain ID", NULL };
442 static CharPtr  snpRadios [] = { "Summary", "Fields", "SNP ID", NULL };
443 static CharPtr  journalsRadios [] = { "Summary", "Fields", "Journals ID", NULL };
444 static CharPtr  unigeneRadios [] = { "Summary", "Fields", "UniGene ID", NULL };
445 static CharPtr  pmcRadios [] = { "Summary", "Fields", "PMC ID", NULL };
446 static CharPtr  ncbisearchRadios [] = { "Summary", "Fields", "Unique ID", NULL };
447 static CharPtr  meshRadios [] = { "Summary", "Fields", "MeSH ID", NULL };
448 static CharPtr  geneRadios [] = { "Summary", "Fields", "Gene ID", NULL };
449 static CharPtr  localBioseqRadios [] = { "FASTA", NULL };
450 
451 static CharPtr  defaultLaunch [] = { "Web Entrez", NULL };
452 static CharPtr  medLaunch [] = { "Local", "Web Entrez", "ASN.1", NULL };
453 static CharPtr  prtLaunch [] = { "Local", "Sequin", "Web Entrez", "ASN.1", NULL };
454 static CharPtr  nucLaunch [] = { "Local", "Sequin", "Web Entrez", "ASN.1", NULL };
455 static CharPtr  strucLaunch [] = { "Cn3D", "Web Entrez", "ASN.1", NULL };
456 static CharPtr  genLaunch [] = { "Local", "Sequin", "Web Entrez", "ASN.1", NULL };
457 static CharPtr  popsetLaunch [] = { "Local", "Sequin", "Web Entrez", "ASN.1", NULL };
458 static CharPtr  omimLaunch [] = { "Web Entrez", "ASN.1", NULL };
459 static CharPtr  taxonomyLaunch [] = { "Web Entrez", NULL };
460 static CharPtr  bookLaunch [] = { "Web Entrez", NULL };
461 static CharPtr  probeLaunch [] = { "Web Entrez", NULL };
462 static CharPtr  domainLaunch [] = { "Web Entrez", NULL };
463 static CharPtr  stsLaunch [] = { "Web Entrez", NULL };
464 static CharPtr  cddLaunch [] = { "Web Entrez", NULL };
465 static CharPtr  snpLaunch [] = { "Web Entrez", NULL };
466 static CharPtr  journalsLaunch [] = { "Web Entrez", NULL };
467 static CharPtr  unigeneLaunch [] = { "Web Entrez", NULL };
468 static CharPtr  pmcLaunch [] = { "Web Entrez", NULL };
469 static CharPtr  ncbisearchLaunch [] = { "Web Entrez", NULL };
470 static CharPtr  meshLaunch [] = { "Web Entrez", NULL };
471 static CharPtr  geneLaunch [] = { "Web Entrez", NULL };
472 
473 /*-----------------------------------*/
474 /* Data structures used to keep info */
475 /* about the current window.         */
476 /*-----------------------------------*/
477 
478 typedef struct docsumstatedata {
479   unsigned int    checked:1;
480   unsigned int    hasAbstract:1;
481   unsigned int    noSuchUid:1;
482 } DocSumStateData, PNTR DocSumStateDataPtr;
483 
484 typedef struct summformdata {
485   FORM_MESSAGE_BLOCK
486   E2NamedUidListProc    refineUidProc;
487   PopuP                 target;
488   DoC                   docsum;
489   PopuP                 formatPopups [MAX_DBS + 1];
490   PopuP                 launchPopups [MAX_DBS + 1];
491   CharPtr               label;
492   GrouP                 controls;
493 
494   Int2                  dsClickItem;
495   Int2                  dsClickRow;
496   Int2                  dsClickCol;
497   Boolean               wasDoubleClick;
498 
499   Boolean               usingDelay;
500   Int2                  retrieveMode;
501 
502   ButtoN                retrieve;
503   ButtoN                refine;
504 
505   EnumFieldAssocPtr     dbalist;
506 
507   Int4Ptr               uids;
508   BoolPtr               formatted;
509   SimpleSeqPtr PNTR     simple;
510   DocSumStateDataPtr    state;
511   Int2                  numUids;
512   Int2                  numParents;
513 
514   Int4Ptr               neighbors;
515   Int2                  numNeighbors;
516   Int2                  neighborDb;
517   Int2                  currDb;
518 
519   Int2                  lineHeight;
520   Int2                  linesPerIcon;
521 
522   CharPtr               historyFile;
523   Int4Ptr               historyOffsets;
524   Int2                  generations;
525   Int2                  present;
526 
527   ButtoN                nextBtn;
528   ButtoN                prevBtn;
529 
530   FonT                  docsumFont;
531 
532   Entrez2DocsumListPtr  tempE2DLP;
533 } SummFormData, PNTR SummFormPtr;
534 
535 
536 extern Entrez2ReplyPtr SpecialEntrezSynchronousQuery (
537   Entrez2RequestPtr e2rq
538 );
539 
540 /*==================================================================*/
541 /*                                                                  */
542 /*  BioseqFindEntityByGi () -                                       */
543 /*                                                                  */
544 /*==================================================================*/
545 
BioseqFindEntityByGi(Int4 uid,Uint4Ptr itemIDptr)546 static Uint2 BioseqFindEntityByGi (Int4 uid, Uint4Ptr itemIDptr)
547 
548 {
549   ValNode  vn;
550 
551   if (uid <= 0) return 0;
552   vn.choice = SEQID_GI;
553   vn.data.intvalue = uid;
554   return BioseqFindEntity (&vn, itemIDptr);
555 }
556 
557 /*==================================================================*/
558 /*                                                                  */
559 /*  SetDefaultFailureMessage () -                                   */
560 /*                                                                  */
561 /*==================================================================*/
562 
SetDefaultFailureMessage(SummFormPtr sfp,Int2 item,CharPtr prefix)563 static CharPtr SetDefaultFailureMessage (SummFormPtr sfp, Int2 item, CharPtr prefix)
564 
565 {
566   Char          buf [40];
567   CharPtr       dbname = NULL;
568   SimpleSeqPtr  ssp;
569   Char          tmp [64];
570   Int4          uid;
571 
572   tmp [0] = '\0';
573   if (prefix == NULL)
574     prefix = "";
575 
576   if (sfp == NULL)
577     return StringSave ("?");
578 
579   if (sfp->currDb >= 0 && sfp->currDb < MAX_DBS) {
580     dbname = GetEnumName ((UIEnum) sfp->currDb, sfp->dbalist);
581   }
582 
583   if (dbname == NULL) {
584     dbname = "[?]";
585   }
586 
587   if (item < 1) {
588     sprintf (tmp, "%sItem < 1 for database %s", prefix, dbname);
589   } else if (sfp->uids != NULL && sfp->simple == NULL) {
590     uid = sfp->uids [item - 1];
591     if (uid < 1) {
592       sprintf (tmp, "%sID < 1 for database %s", prefix, dbname);
593     } else {
594       sprintf (tmp, "%sFailure for ID %ld in %s database", prefix, (long) uid, dbname);
595     }
596   } else if (sfp->simple != NULL && sfp->uids == NULL) {
597     ssp = sfp->simple [item - 1];
598     if (ssp == NULL) {
599       sprintf ("%sIncorrect seq-entry for database %s", prefix, dbname);
600     } else {
601       StringCpy (buf, "?");
602       if (ssp->numid > 0 && ssp->bestid < ssp->numid) {
603         StringNCpy_0 (buf, ssp->id [ssp->bestid], sizeof (buf));
604       }
605       sprintf ("%sProblem with sequence %s in %s database", prefix, buf, dbname);
606     }
607   } else {
608     sprintf ("%sInternal confusion for database %s", prefix, dbname);
609   }
610 
611   return StringSave (tmp);
612 }
613 
614 /*==================================================================*/
615 /*                                                                  */
616 /*  DoDrawCheck () -                                                */
617 /*                                                                  */
618 /*==================================================================*/
619 
DoDrawCheck(SummFormPtr sfp,RectPtr r,Int2 item,Int2 frst,Boolean docsum)620 static void DoDrawCheck (SummFormPtr sfp, RectPtr r, Int2 item, Int2 frst, Boolean docsum)
621 
622 {
623   Int2  checked;
624   RecT  rct;
625 
626   if (sfp == NULL || sfp->state == NULL) return;
627   if (item < 1 || item > sfp->numUids) return;
628   checked = sfp->state [item - 1].checked;
629   if (frst == 0) {
630     rct = *r;
631     rct.right = rct.left + sfp->lineHeight;
632     rct.bottom = rct.top + sfp->lineHeight;
633     if (RectInRgn (&rct, updateRgn)) {
634       FrameRect (&rct);
635       if (checked) {
636         MoveTo (rct.left, rct.top);
637         LineTo (rct.right - 1, rct.bottom - 1);
638         MoveTo (rct.left, rct.bottom - 1);
639         LineTo (rct.right - 1, rct.top);
640       }
641     }
642     if (item <= sfp->numParents) {
643       rct = *r;
644       if (docsum) {
645         rct.left += docsumColFmt [0].pixInset - 6;
646         rct.top += (sfp->lineHeight - 4) / 2;
647         rct.right = rct.left + 4;
648         rct.bottom = rct.top + 4;
649       } else {
650         rct.left += textColFmt [0].pixInset - 6;
651         rct.top += (sfp->lineHeight - 4) / 2;
652         rct.right = rct.left + 4;
653         rct.bottom = rct.top + 4;
654       }
655       if (RectInRgn (&rct, updateRgn)) {
656         PaintOval (&rct);
657       }
658     }
659   }
660 }
661 
662 /*==================================================================*/
663 /*                                                                  */
664 /*  DrawLocalCheck () -                                             */
665 /*                                                                  */
666 /*==================================================================*/
667 
DrawLocalCheck(SummFormPtr sfp,RectPtr r,Int2 item,Int2 frst,Boolean docsum)668 static void DrawLocalCheck (SummFormPtr sfp, RectPtr r, Int2 item, Int2 frst, Boolean docsum)
669 
670 {
671   SimpleSeqPtr  ssp;
672 
673   if (sfp == NULL || sfp->simple == NULL || sfp->state == NULL) return;
674   if (item < 1 || item > sfp->numUids) return;
675   ssp = sfp->simple [item - 1];
676   if (ssp == NULL) return;
677   DoDrawCheck (sfp, r, item, frst, docsum);
678 }
679 
680 /*==================================================================*/
681 /*                                                                  */
682 /*  DrawUidCheck () -                                               */
683 /*                                                                  */
684 /*==================================================================*/
685 
DrawUidCheck(SummFormPtr sfp,RectPtr r,Int2 item,Int2 frst,Boolean docsum)686 static void DrawUidCheck (SummFormPtr sfp, RectPtr r, Int2 item, Int2 frst, Boolean docsum)
687 
688 {
689   Int4  uid;
690 
691   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return;
692   if (item < 1 || item > sfp->numUids) return;
693   uid = sfp->uids [item - 1];
694   if (uid < 1) return;
695   DoDrawCheck (sfp, r, item, frst, docsum);
696 }
697 
698 /*==================================================================*/
699 /*                                                                  */
700 /*  DrawIcon () - Figures out which icon to draw (based on the      */
701 /*               current db) and then draws it in the proper spot.  */
702 /*                                                                  */
703 /*==================================================================*/
704 
DrawIcon(SummFormPtr sfp,RectPtr r,Int2 item,Int2 frst)705 static void DrawIcon (SummFormPtr sfp, RectPtr r, Int2 item, Int2 frst)
706 
707 {
708   Int2      db;
709   CharPtr   dbName;
710   Int2      hasAbstract;
711   Uint1Ptr  icon;
712   RecT      rct;
713   Int4      uid;
714 
715   /*------------------------------------*/
716   /* Perform sanity check on parameters */
717   /*------------------------------------*/
718 
719   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return;
720   if (item < 1 || item > sfp->numUids) return;
721   if (frst >= sfp->linesPerIcon) return;
722 
723   /*---------------------------------*/
724   /* Get the current state of things */
725   /*---------------------------------*/
726 
727   db = sfp->currDb;
728   uid = sfp->uids [item - 1];
729   hasAbstract = sfp->state [item - 1].hasAbstract;
730   if (uid < 1) return;
731 
732   /*-----------------------------*/
733   /* Calculate which icon to use */
734   /*-----------------------------*/
735 
736   dbName = DBGetNameFromID (db);
737 
738   if (StringICmp (dbName, "PubMed") == 0) {
739     if (hasAbstract)
740       icon = hasabstract;
741     else
742       icon = noabstract;
743   } else if (StringICmp (dbName, "Protein") == 0)
744     icon = proteinicon;
745   else if (StringICmp (dbName, "Nucleotide") == 0)
746     icon = dnaicon;
747   else if (StringICmp (dbName, "nuccore") == 0)
748     icon = dnaicon;
749   else if (StringICmp (dbName, "Structure") == 0)
750     icon = threedicon;
751   else if (StringICmp (dbName, "Genome") == 0)
752     icon = genomeicon;
753   else if (StringICmp (dbName, "Popset") == 0)
754     icon = popseticon;
755   else if (StringICmp (dbName, "OMIM") == 0)
756     icon = omimicon;
757   else if (StringICmp (dbName, "Taxonomy") == 0)
758     icon = taxonomyicon;
759   else if (StringICmp (dbName, "Books") == 0)
760     icon = booksicon;
761   else if (StringICmp (dbName, "geo") == 0)
762     icon = probeicon;
763   else if (StringICmp (dbName, "domains") == 0)
764     icon = domainicon;
765   else if (StringICmp (dbName, "unists") == 0)
766     icon = stsicon;
767   else if (StringICmp (dbName, "cdd") == 0)
768     icon = cddicon;
769   else if (StringICmp (dbName, "snp") == 0)
770     icon = snpicon;
771   else if (StringICmp (dbName, "journals") == 0)
772     icon = journalsicon;
773   else if (StringICmp (dbName, "unigene") == 0)
774     icon = unigeneicon;
775   else if (StringICmp (dbName, "PMC") == 0)
776     icon = pmcicon;
777   else if (StringICmp (dbName, "ncbisearch") == 0)
778     icon = ncbisearchicon;
779   else if (StringICmp (dbName, "mesh") == 0)
780     icon = meshicon;
781   else if (StringICmp (dbName, "gene") == 0)
782     icon = geneicon;
783   else
784     icon = genericon;
785 
786   /*------------------*/
787   /* Display the icon */
788   /*------------------*/
789 
790   rct = *r;
791   rct.left += 3 * stdCharWidth - 8;
792   rct.right = rct.left + 32;
793   rct.bottom = MIN (rct.bottom, rct.top + 22 - frst * sfp->lineHeight);
794   if (RectInRgn (&rct, updateRgn)) {
795     if (icon != NULL) {
796       CopyBits (&rct, icon + 4 * frst * sfp->lineHeight);
797     }
798   }
799 }
800 
801 /*==================================================================*/
802 /*                                                                  */
803 /*  DrawTextSum () -                                                */
804 /*                                                                  */
805 /*==================================================================*/
806 
DrawTextSum(DoC d,RectPtr r,Int2 item,Int2 frst)807 static void DrawTextSum (DoC d, RectPtr r, Int2 item, Int2 frst)
808 
809 {
810   SummFormPtr  sfp;
811 
812   sfp = (SummFormPtr) GetObjectExtra (d);
813   DrawUidCheck (sfp, r, item, frst, FALSE);
814 }
815 
816 /*==================================================================*/
817 /*                                                                  */
818 /*  DrawLocalSum () -                                               */
819 /*                                                                  */
820 /*==================================================================*/
821 
DrawLocalSum(DoC d,RectPtr r,Int2 item,Int2 frst)822 static void DrawLocalSum (DoC d, RectPtr r, Int2 item, Int2 frst)
823 
824 {
825   SummFormPtr  sfp;
826 
827   sfp = (SummFormPtr) GetObjectExtra (d);
828   DrawLocalCheck (sfp, r, item, frst, FALSE);
829 }
830 
831 /*==================================================================*/
832 /*                                                                  */
833 /*  DrawDocSum () -                                                 */
834 /*                                                                  */
835 /*==================================================================*/
836 
DrawDocSum(DoC d,RectPtr r,Int2 item,Int2 frst)837 static void DrawDocSum (DoC d, RectPtr r, Int2 item, Int2 frst)
838 
839 {
840   SummFormPtr  sfp;
841 
842   sfp = (SummFormPtr) GetObjectExtra (d);
843   DrawUidCheck (sfp, r, item, frst, TRUE);
844   DrawIcon (sfp, r, item, frst);
845 }
846 
847 /*==================================================================*/
848 /*                                                                  */
849 /*  Query_FetchDocSum () -                                          */
850 /*  Query_FetchFields () -                                          */
851 /*                                                                  */
852 /*==================================================================*/
853 
FormatDocsum(Entrez2DocsumPtr e2DocsumPtr)854 static CharPtr FormatDocsum (Entrez2DocsumPtr e2DocsumPtr)
855 
856 {
857   Entrez2DocsumDataPtr  e2DocsumDataPtr;
858   CharPtr               accession;
859   CharPtr               accession1;
860   CharPtr               authors;
861   CharPtr               book;
862   CharPtr               caption;
863   Char                  ch;
864   CharPtr               clustid;
865   Int2                  commas;
866   CharPtr               comname;
867   CharPtr               cpt;
868   CharPtr               dcsum;
869   CharPtr               description;
870   CharPtr               etal;
871   CharPtr               extra;
872   size_t                len;
873   CharPtr               marker;
874   CharPtr               mrnasrc1;
875   CharPtr               mrnasrc2;
876   CharPtr               name;
877   CharPtr               oid;
878   CharPtr               pdbacc;
879   CharPtr               pdbdescr;
880   CharPtr               rank;
881   CharPtr               sciname;
882   CharPtr               scopenote;
883   CharPtr               snpid;
884   CharPtr               str;
885   CharPtr               taxid;
886   CharPtr               title;
887   CharPtr               title1;
888   CharPtr               ttl;
889   CharPtr               tmp;
890   Uint4                 uid;
891   Char                  uidbuf [32];
892 
893   if (e2DocsumPtr == NULL) return NULL;
894 
895   uid = e2DocsumPtr->uid;
896 
897   cpt = NULL;
898   ttl = NULL;
899 
900   accession = NULL;
901   accession1 = NULL;
902   authors = NULL;
903   book = NULL;
904   caption = NULL;
905   comname = NULL;
906   extra = NULL;
907   mrnasrc1 = NULL;
908   mrnasrc2 = NULL;
909   oid = NULL;
910   pdbacc = NULL;
911   pdbdescr = NULL;
912   rank = NULL;
913   sciname = NULL;
914   taxid = NULL;
915   clustid = NULL;
916   marker = NULL;
917   snpid = NULL;
918   dcsum = NULL;
919   title = NULL;
920   title1 = NULL;
921   name = NULL;
922   description = NULL;
923   scopenote = NULL;
924 
925   for (e2DocsumDataPtr = e2DocsumPtr->docsum_data; e2DocsumDataPtr != NULL; e2DocsumDataPtr = e2DocsumDataPtr->next) {
926     if (StringHasNoText (e2DocsumDataPtr->field_value)) continue;
927     if (StringICmp (e2DocsumDataPtr->field_name, "Caption") == 0) {
928       caption = e2DocsumDataPtr->field_value;
929     } else if (StringICmp (e2DocsumDataPtr->field_name, "Title") == 0) {
930       title = e2DocsumDataPtr->field_value;
931     } else if (StringICmp (e2DocsumDataPtr->field_name, "Authors") == 0 ||
932                StringICmp (e2DocsumDataPtr->field_name, "Author") == 0) {
933       authors = e2DocsumDataPtr->field_value;
934     } else if (StringICmp (e2DocsumDataPtr->field_name, "Accession") == 0) {
935       accession = e2DocsumDataPtr->field_value;
936     } else if (StringICmp (e2DocsumDataPtr->field_name, "Extra") == 0) {
937       extra = e2DocsumDataPtr->field_value;
938     } else if (StringICmp (e2DocsumDataPtr->field_name, "TaxID") == 0) {
939       taxid = e2DocsumDataPtr->field_value;
940     } else if (StringICmp (e2DocsumDataPtr->field_name, "CID") == 0 ||
941                StringICmp (e2DocsumDataPtr->field_name, "CLUSTERID") == 0) {
942       clustid = e2DocsumDataPtr->field_value;
943     } else if (StringICmp (e2DocsumDataPtr->field_name, "ScientificName") == 0) {
944       sciname = e2DocsumDataPtr->field_value;
945     } else if (StringICmp (e2DocsumDataPtr->field_name, "CommonName") == 0) {
946       comname = e2DocsumDataPtr->field_value;
947     } else if (StringICmp (e2DocsumDataPtr->field_name, "Rank") == 0) {
948       rank = e2DocsumDataPtr->field_value;
949     } else if (StringICmp (e2DocsumDataPtr->field_name, "Oid") == 0) {
950       oid = e2DocsumDataPtr->field_value;
951     } else if (StringICmp (e2DocsumDataPtr->field_name, "Accession1") == 0) {
952       accession1 = e2DocsumDataPtr->field_value;
953     } else if (StringICmp (e2DocsumDataPtr->field_name, "Title1") == 0) {
954       title1 = e2DocsumDataPtr->field_value;
955     } else if (StringICmp (e2DocsumDataPtr->field_name, "mRNASource1") == 0) {
956       mrnasrc1 = e2DocsumDataPtr->field_value;
957     } else if (StringICmp (e2DocsumDataPtr->field_name, "mRNASource2") == 0) {
958       mrnasrc2 = e2DocsumDataPtr->field_value;
959     } else if (StringICmp (e2DocsumDataPtr->field_name, "Book") == 0) {
960       book = e2DocsumDataPtr->field_value;
961     } else if (StringICmp (e2DocsumDataPtr->field_name, "Marker_Title") == 0) {
962       marker = e2DocsumDataPtr->field_value;
963     } else if (StringICmp (e2DocsumDataPtr->field_name, "SNP_ID") == 0) {
964       snpid = e2DocsumDataPtr->field_value;
965     } else if (StringICmp (e2DocsumDataPtr->field_name, "DOCSUM") == 0) {
966       dcsum = e2DocsumDataPtr->field_value;
967     } else if (StringICmp (e2DocsumDataPtr->field_name, "Name") == 0) {
968       name = e2DocsumDataPtr->field_value;
969     } else if (StringICmp (e2DocsumDataPtr->field_name, "Description") == 0) {
970       description = e2DocsumDataPtr->field_value;
971     } else if (StringICmp (e2DocsumDataPtr->field_name, "ScopeNote") == 0) {
972       scopenote = e2DocsumDataPtr->field_value;
973     } else if (StringICmp (e2DocsumDataPtr->field_name, "PdbAcc") == 0) {
974       pdbacc = e2DocsumDataPtr->field_value;
975     } else if (StringICmp (e2DocsumDataPtr->field_name, "PdbDescr") == 0) {
976       pdbdescr = e2DocsumDataPtr->field_value;
977     }
978   }
979 
980   cpt = caption;
981 
982   ttl = title;
983 
984   if (StringHasNoText (cpt)) {
985     cpt = accession1;
986   }
987   if (StringHasNoText (cpt)) {
988     cpt = authors;
989   }
990   if (StringHasNoText (cpt)) {
991     cpt = accession;
992   }
993   if (StringHasNoText (cpt)) {
994     cpt = clustid;
995   }
996   if (StringHasNoText (cpt)) {
997     cpt = taxid;
998   }
999   if (StringHasNoText (cpt)) {
1000     cpt = oid;
1001   }
1002   if (StringHasNoText (cpt)) {
1003     cpt = book;
1004   }
1005   if (StringHasNoText (cpt)) {
1006     cpt = snpid;
1007   }
1008   if (StringHasNoText (cpt) && (! StringHasNoText (title)) && (! StringHasNoText (description))) {
1009     cpt = title;
1010     ttl = description;
1011   }
1012   if (StringHasNoText (cpt) && (! StringHasNoText (name)) && (! StringHasNoText (description))) {
1013     cpt = name;
1014     ttl = description;
1015   }
1016   if (StringHasNoText (cpt)) {
1017     cpt = pdbacc;
1018   }
1019   if (StringHasNoText (cpt)) {
1020     sprintf (uidbuf, "%ud", uid);
1021     cpt = uidbuf;
1022   }
1023   if (StringHasNoText (cpt)) {
1024     cpt = "?";
1025   }
1026 
1027   if (StringHasNoText (ttl)) {
1028     ttl = sciname;
1029   }
1030   if (StringHasNoText (ttl)) {
1031     ttl = mrnasrc1;
1032   }
1033   if (StringHasNoText (ttl)) {
1034     ttl = title1;
1035   }
1036   if (StringHasNoText (ttl)) {
1037     ttl = marker;
1038   }
1039   if (StringHasNoText (ttl)) {
1040     ttl = dcsum;
1041   }
1042   if (StringHasNoText (ttl)) {
1043     ttl = scopenote;
1044   }
1045   if (StringHasNoText (ttl)) {
1046     ttl = pdbdescr;
1047   }
1048   if (StringHasNoText (ttl)) {
1049     ttl = "?";
1050   }
1051 
1052   len = StringLen (cpt) + StringLen (ttl) + StringLen (extra) +
1053         StringLen (mrnasrc2) + StringLen (comname) +
1054         StringLen (", et al.") + StringLen ("vs. ") +
1055         StringLen (" []") + StringLen ("rs");
1056   str = MemNew (len + 10);
1057   if (str != NULL) {
1058     str [0] = '\0';
1059     if (cpt == snpid) {
1060       StringCat (str, "rs");
1061     }
1062     StringCat (str, cpt);
1063     if (cpt == authors) {
1064       if (StringLen (str) > 64) {
1065         commas = 0;
1066         etal = NULL;
1067         for (tmp = str, ch = *tmp; ch != '\0'; tmp++, ch = *tmp) {
1068           if (ch == ',') {
1069             commas++;
1070             if (etal == NULL) {
1071               etal = tmp;
1072             }
1073           }
1074         }
1075         if (commas > 2 && etal != NULL) {
1076           *etal = '\0';
1077           StringCat (str, ", et al.");
1078          }
1079       }
1080     }
1081     StringCat (str, "\t");
1082     StringCat (str, ttl);
1083     if (ttl == mrnasrc1) {
1084       if (! StringHasNoText (mrnasrc2)) {
1085         StringCat (str, "vs. ");
1086         StringCat (str, mrnasrc2);
1087       }
1088     } else if (ttl == title) {
1089       if (! StringHasNoText (extra)) {
1090         StringCat (str, "\r");
1091         StringCat (str, extra);
1092       }
1093     } else if (ttl == sciname) {
1094       if (StringICmp (rank, "species") == 0) {
1095         if (! StringHasNoText (comname)) {
1096           StringCat (str, " [");
1097           StringCat (str, comname);
1098           StringCat (str, "]");
1099         }
1100       }
1101     }
1102   }
1103 
1104   return str;
1105 }
1106 
FormatFields(Entrez2DocsumPtr e2DocsumPtr)1107 static CharPtr FormatFields (Entrez2DocsumPtr e2DocsumPtr)
1108 
1109 {
1110   Entrez2DocsumDataPtr  e2DocsumDataPtr;
1111   size_t                len;
1112   CharPtr               str;
1113 
1114   if (e2DocsumPtr == NULL) return NULL;
1115 
1116   len = 0;
1117   for (e2DocsumDataPtr = e2DocsumPtr->docsum_data; e2DocsumDataPtr != NULL; e2DocsumDataPtr = e2DocsumDataPtr->next) {
1118     if (StringHasNoText (e2DocsumDataPtr->field_name)) continue;
1119     if (StringHasNoText (e2DocsumDataPtr->field_value)) continue;
1120     len += StringLen (e2DocsumDataPtr->field_name) + StringLen (e2DocsumDataPtr->field_value) + 3;
1121   }
1122   str = MemNew (len + 5);
1123   if (str != NULL) {
1124     for (e2DocsumDataPtr = e2DocsumPtr->docsum_data; e2DocsumDataPtr != NULL; e2DocsumDataPtr = e2DocsumDataPtr->next) {
1125       if (StringHasNoText (e2DocsumDataPtr->field_name)) continue;
1126       if (StringHasNoText (e2DocsumDataPtr->field_value)) continue;
1127       StringCat (str, e2DocsumDataPtr->field_name);
1128       StringCat (str, "\t");
1129       StringCat (str, e2DocsumDataPtr->field_value);
1130       StringCat (str, "\n");
1131     }
1132   }
1133 
1134   return str;
1135 }
1136 
1137 typedef CharPtr (*FormatE2DSPProc) (Entrez2DocsumPtr e2DocsumPtr);
1138 
Query_FetchDocSumCommon(DoC d,Int2 item,FormatE2DSPProc proc)1139 static CharPtr Query_FetchDocSumCommon (DoC d, Int2 item, FormatE2DSPProc proc)
1140 
1141 {
1142   Int2                  attributes;
1143   Entrez2RequestPtr     e2RequestPtr = NULL;
1144   Entrez2ReplyPtr       e2ReplyPtr;
1145   Entrez2DocsumDataPtr  e2DocsumDataPtr;
1146   Entrez2DocsumListPtr  e2DocsumListPtr;
1147   Entrez2DocsumPtr      e2DocsumPtr;
1148   CharPtr               dbName;
1149   CharPtr               failed;
1150   Int2                  i;
1151   Int2                  j;
1152   Int2                  numToFetch;
1153   SummFormPtr           sfp;
1154   CharPtr               str;
1155   Int4                  uid;
1156   Int4                  uids [30];
1157 
1158   /*------------------------------------------*/
1159   /* Make sure that initial conditions are ok */
1160   /*------------------------------------------*/
1161 
1162   sfp = (SummFormPtr) GetObjectExtra (d);
1163   failed = SetDefaultFailureMessage (sfp, item, "\r\t");
1164   if (proc == NULL) return failed;
1165   if (sfp == NULL || sfp->uids == NULL ||
1166       sfp->state == NULL || sfp->formatted == NULL) return failed;
1167   if (item < 1) return failed;
1168 
1169   /*----------------------------*/
1170   /* Fetch the document summary */
1171   /* for the request UID.       */
1172   /*----------------------------*/
1173 
1174   uid = sfp->uids [item - 1];
1175   dbName = DBGetNameFromID (sfp->currDb);
1176 
1177   /* check existing cache */
1178 
1179   if (sfp->tempE2DLP != NULL) {
1180     e2DocsumListPtr = sfp->tempE2DLP;
1181     for (e2DocsumPtr = e2DocsumListPtr->list; e2DocsumPtr != NULL; e2DocsumPtr = e2DocsumPtr->next) {
1182       if (uid == e2DocsumPtr->uid) {
1183         str = proc (e2DocsumPtr);
1184         /* sfp->state [item - 1].hasAbstract = (Boolean) (! e2DocsumPtr->no_abstract); */
1185         sfp->state [item - 1].hasAbstract = FALSE;
1186         for (e2DocsumDataPtr = e2DocsumPtr->docsum_data; e2DocsumDataPtr != NULL; e2DocsumDataPtr = e2DocsumDataPtr->next) {
1187           if (StringHasNoText (e2DocsumDataPtr->field_value)) continue;
1188           if (StringICmp (e2DocsumDataPtr->field_name, "Attributes") == 0) {
1189             if (StrToInt (e2DocsumDataPtr->field_value, &attributes)) {
1190               if ((attributes & 1) != 0) {
1191                 sfp->state [item - 1].hasAbstract = TRUE;
1192               }
1193             }
1194           }
1195         }
1196         sfp->formatted [item - 1] = TRUE;
1197         MemFree (failed);
1198         return str;
1199       }
1200     }
1201   }
1202 
1203   sfp->tempE2DLP = Entrez2DocsumListFree (sfp->tempE2DLP);
1204 
1205   /* create new request */
1206 
1207   uids [0] = uid;
1208   numToFetch = 1;
1209   for (i = item, j = 0; i < sfp->numUids && j < 20 && numToFetch < 20; i++, j++) {
1210     if (! sfp->formatted [i]) {
1211       uids [numToFetch] = sfp->uids [i];
1212       numToFetch++;
1213     }
1214   }
1215   for (i = item - 1, j = 0; i >= 0 && j < 20 && numToFetch < 30; i--, j++) {
1216     if (! sfp->formatted [i]) {
1217       uids [numToFetch] = sfp->uids [i];
1218       numToFetch++;
1219     }
1220   }
1221 
1222   /* accelerate docsum page requesting several at once */
1223 
1224 #ifdef WIN_MOTIF
1225   if ((getenv ("NCBI_ENTREZ_SLOW_DOCSUMS")) == NULL) {
1226     e2RequestPtr = EntrezCreateDocSumRequest (dbName, 0, (Int4) numToFetch, uids, NULL);
1227   }
1228 #else
1229   e2RequestPtr = EntrezCreateDocSumRequest (dbName, 0, (Int4) numToFetch, uids, NULL);
1230 #endif
1231 
1232   /* one at a time request if not grouping, to make sure server did not slow down again */
1233 
1234   if (e2RequestPtr == NULL) {
1235     e2RequestPtr = EntrezCreateDocSumRequest (dbName, uid, 0, NULL, NULL);
1236   }
1237 
1238   if (e2RequestPtr == NULL) return failed;
1239 
1240   if (ShowASN () == TRUE)
1241     DisplayEntrezRequest (e2RequestPtr);
1242 
1243   e2ReplyPtr = SpecialEntrezSynchronousQuery (e2RequestPtr);
1244   if (e2ReplyPtr == NULL) return failed;
1245 
1246   if (ShowASN () == TRUE)
1247     DisplayEntrezReply (e2ReplyPtr);
1248 
1249   sfp->tempE2DLP = EntrezExtractDocsumReply (e2ReplyPtr);
1250   Entrez2RequestFree (e2RequestPtr);
1251   if (sfp->tempE2DLP == NULL) return failed;
1252 
1253   /* check new cache */
1254 
1255   if (sfp->tempE2DLP != NULL) {
1256     e2DocsumListPtr = sfp->tempE2DLP;
1257     for (e2DocsumPtr = e2DocsumListPtr->list; e2DocsumPtr != NULL; e2DocsumPtr = e2DocsumPtr->next) {
1258       if (uid == e2DocsumPtr->uid) {
1259         str = proc (e2DocsumPtr);
1260         /* sfp->state [item - 1].hasAbstract = (Boolean) (! e2DocsumPtr->no_abstract); */
1261         sfp->state [item - 1].hasAbstract = FALSE;
1262         for (e2DocsumDataPtr = e2DocsumPtr->docsum_data; e2DocsumDataPtr != NULL; e2DocsumDataPtr = e2DocsumDataPtr->next) {
1263           if (StringHasNoText (e2DocsumDataPtr->field_value)) continue;
1264           if (StringICmp (e2DocsumDataPtr->field_name, "Attributes") == 0) {
1265             if (StrToInt (e2DocsumDataPtr->field_value, &attributes)) {
1266               if ((attributes & 1) != 0) {
1267                 sfp->state [item - 1].hasAbstract = TRUE;
1268               }
1269             }
1270           }
1271         }
1272         sfp->formatted [item - 1] = TRUE;
1273         MemFree (failed);
1274         return str;
1275       }
1276     }
1277   }
1278 
1279   return failed;
1280 }
1281 
Query_FetchDocSum(DoC d,Int2 item,Pointer ptr)1282 static CharPtr Query_FetchDocSum (DoC d, Int2 item, Pointer ptr)
1283 
1284 {
1285   return Query_FetchDocSumCommon (d, item, FormatDocsum);
1286 }
1287 
Query_FetchFields(DoC d,Int2 item,Pointer ptr)1288 static CharPtr Query_FetchFields (DoC d, Int2 item, Pointer ptr)
1289 
1290 {
1291   return Query_FetchDocSumCommon (d, item, FormatFields);
1292 }
1293 
1294 /*==================================================================*/
1295 /*                                                                  */
1296 /*  FileToString () -                                               */
1297 /*                                                                  */
1298 /*==================================================================*/
1299 
1300 static CharPtr file_is_too_long_mssg =
1301 "The record is too large to display in this format in the document summary window.\n\
1302 Please double click here to launch a separate viewer that can display this record.";
1303 
FileToString(CharPtr path)1304 static CharPtr FileToString (CharPtr path)
1305 
1306 {
1307   Int2     actual;
1308   FILE     *fp;
1309   Int8     len;
1310   CharPtr  ptr;
1311 
1312   if (path == NULL) return NULL;
1313   ptr = NULL;
1314   len = FileLength (path);
1315   if (len > 0 && len < MAXALLOC) {
1316     if (len > 65000) {
1317       ptr = StringSave (file_is_too_long_mssg);
1318     } else {
1319       fp = FileOpen (path, "r");
1320       if (fp != NULL) {
1321         ptr = MemNew (sizeof (Char) * (size_t) (len + 4));
1322         if (ptr != NULL) {
1323           actual = FileRead (ptr, 1, (size_t) len, fp);
1324           if (actual > 0 && actual <= len) {
1325             ptr [actual] = '\0';
1326           }
1327         }
1328       FileClose (fp);
1329       }
1330     }
1331   }
1332   return ptr;
1333 }
1334 
1335 /*==================================================================*/
1336 /*                                                                  */
1337 /*  FetchUid () -                                                   */
1338 /*                                                                  */
1339 /*==================================================================*/
1340 
FetchUid(DoC d,Int2 item,Pointer ptr)1341 static CharPtr FetchUid (DoC d, Int2 item, Pointer ptr)
1342 
1343 {
1344   CharPtr         failed;
1345   SummFormPtr     sfp;
1346   Char            str [64];
1347   Int4            uid;
1348 
1349   /*--------------------------*/
1350   /* Check initial conditions */
1351   /*--------------------------*/
1352 
1353   sfp = (SummFormPtr) GetObjectExtra (d);
1354   failed = SetDefaultFailureMessage (sfp, item, NULL);
1355   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
1356   if (item < 1) return failed;
1357 
1358   /*------------------------------------*/
1359   /* Get the UID for the requested item */
1360   /*------------------------------------*/
1361 
1362   uid = sfp->uids [item - 1];
1363   if (uid < 1) return failed;
1364   sprintf (str, "%ld\n", (long) uid);
1365 
1366   /*----------------------------------*/
1367   /* Clean up and return successfully */
1368   /*----------------------------------*/
1369 
1370   MemFree (failed);
1371   return StringSave (str);
1372 }
1373 
1374 /*==================================================================*/
1375 /*                                                                  */
1376 /*  FetchPubMed () -                                                */
1377 /*                                                                  */
1378 /*==================================================================*/
1379 
1380 typedef Boolean (*FormatMedlineProc) (MedlineEntryPtr, FILE*);
1381 
FetchPubMed(DoC d,Int2 item,Pointer ptr,FormatMedlineProc func)1382 static CharPtr FetchPubMed (DoC d, Int2 item, Pointer ptr, FormatMedlineProc func)
1383 
1384 {
1385   CharPtr         failed;
1386   FILE           *fp;
1387   Char            path [PATH_MAX];
1388   PubmedEntryPtr  pep;
1389   SummFormPtr     sfp;
1390   CharPtr         str;
1391   Int4            uid;
1392 
1393   /*--------------------------*/
1394   /* Check initial conditions */
1395   /*--------------------------*/
1396 
1397   sfp = (SummFormPtr) GetObjectExtra (d);
1398   failed = SetDefaultFailureMessage (sfp, item, NULL);
1399 
1400   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
1401   if (item < 1) return failed;
1402 
1403   uid = sfp->uids [item - 1];
1404 
1405   if ((pep = PubMedSynchronousQuery (uid)) == NULL) return failed;
1406 
1407   /*------------------------*/
1408   /* Store to temp file and */
1409   /* then read back in.     */
1410   /*------------------------*/
1411 
1412   str = NULL;
1413   TmpNam (path);
1414   fp = FileOpen (path, "w");
1415   if (fp != NULL) {
1416     if (func ((MedlineEntryPtr) pep->medent, fp)) {
1417       FileClose (fp);
1418       str = FileToString (path);
1419     } else {
1420       FileClose (fp);
1421     }
1422   }
1423   FileRemove (path);
1424   PubmedEntryFree (pep);
1425 
1426   if (str == NULL) return failed;
1427 
1428   MemFree (failed);
1429   return str;
1430 }
1431 
FetchAbstract(DoC d,Int2 item,Pointer ptr)1432 static CharPtr FetchAbstract (DoC d, Int2 item, Pointer ptr)
1433 
1434 {
1435   return FetchPubMed (d, item, ptr, MedlineEntryToAbsFile);
1436 }
1437 
FetchCitation(DoC d,Int2 item,Pointer ptr)1438 static CharPtr FetchCitation (DoC d, Int2 item, Pointer ptr)
1439 
1440 {
1441   return FetchPubMed (d, item, ptr, MedlineEntryToDocFile);
1442 }
1443 
FetchMedline(DoC d,Int2 item,Pointer ptr)1444 static CharPtr FetchMedline (DoC d, Int2 item, Pointer ptr)
1445 
1446 {
1447   return FetchPubMed (d, item, ptr, MedlineEntryToDataFile);
1448 }
1449 
1450 /*==================================================================*/
1451 /*                                                                  */
1452 /*  GetBioseqForUid () -                                            */
1453 /*                                                                  */
1454 /*==================================================================*/
1455 
GetBioseqForUid(SeqEntryPtr topsep,Int4 uid)1456 static BioseqPtr GetBioseqForUid (SeqEntryPtr topsep, Int4 uid)
1457 
1458 {
1459   BioseqPtr       bsp;
1460   SeqEntryPtr     oldsep;
1461   ValNode         vn;
1462 
1463   if (topsep == NULL || uid == 0)
1464     return NULL;
1465   vn.choice = SEQID_GI;
1466   vn.extended = 0;
1467   vn.data.intvalue = uid;
1468   vn.next = NULL;
1469   oldsep = SeqEntrySetScope (topsep);
1470   bsp = BioseqFind (&vn);
1471   SeqEntrySetScope (oldsep);
1472   return bsp;
1473 }
1474 
1475 /*==================================================================*/
1476 /*                                                                  */
1477 /*  GetSequenceComplexity () -                                      */
1478 /*                                                                  */
1479 /*==================================================================*/
1480 
GetSequenceComplexity(void)1481 static Int2 GetSequenceComplexity (void)
1482 
1483 {
1484   Entrez2GlobalsPtr  egp;
1485   Int2               retcode = 0;
1486   Int2               val;
1487 
1488   egp = (Entrez2GlobalsPtr) GetAppProperty ("Entrez2Globals");
1489   if (egp == NULL || egp->seqComplex == NULL) return retcode;
1490   val = GetValue (egp->seqComplex);
1491   switch (val) {
1492     case 1 :
1493       retcode = 0;
1494       break;
1495     case 2 :
1496       retcode = SEQENTRY_READ_NUC_PROT;
1497       break;
1498     case 3 :
1499       retcode = SEQENTRY_READ_SEG_SET;
1500       break;
1501     case 4 :
1502       retcode = SEQENTRY_READ_BIOSEQ;
1503      break;
1504     default :
1505       retcode = 0;
1506       break;
1507   }
1508   return retcode;
1509 }
1510 
1511 /*==================================================================*/
1512 /*                                                                  */
1513 /*  FetchSequence () -                                              */
1514 /*                                                                  */
1515 /*==================================================================*/
1516 
FormatCdsSeq(SeqFeatPtr sfp,Pointer userdata)1517 static void FormatCdsSeq (SeqFeatPtr sfp, Pointer userdata)
1518 
1519 {
1520   BioseqPtr          bsp;
1521   Char               buf [512];
1522   SeqMgrFeatContext  cdscontext;
1523   SeqFeatPtr         gene = NULL;
1524   SeqMgrFeatContext  genecontext;
1525   GeneRefPtr         grp;
1526   FILE               *fp;
1527   SeqIdPtr           sip;
1528   Char               tmp [32];
1529 
1530   if (sfp->data.choice != SEQFEAT_CDREGION) return;
1531   fp = (FILE *) userdata;
1532   bsp = BioseqFindFromSeqLoc (sfp->location);
1533   if (bsp == NULL) return;
1534   if (sfp != SeqMgrGetDesiredFeature (0, bsp, 0, 0, sfp, &cdscontext)) return;
1535   grp = SeqMgrGetGeneXref (sfp);
1536   if (grp == NULL || (! SeqMgrGeneIsSuppressed (grp))) {
1537     gene = SeqMgrGetOverlappingGene (sfp->location, &genecontext);
1538   }
1539   /*
1540   spp = SeqPortNewByLoc (sfp->location, Seq_code_iupacna);
1541   if (spp == NULL) return;
1542   */
1543   sip = SeqIdFindWorst (bsp->id);
1544   SeqIdWrite (sip, buf, PRINTID_TEXTID_ACC_VER, sizeof (buf) - 1);
1545   sprintf (tmp, "_cds_%ld", (long) sfp->idx.itemID);
1546   StringCat (buf, tmp);
1547   FastaFileFunc (bsp, FASTA_ID, buf, sizeof (buf), (Pointer) fp);
1548   buf [0] = '\0';
1549   if (! StringHasNoText (cdscontext.label)) {
1550     StringCat (buf, "[protein=");
1551     StringCat (buf, cdscontext.label);
1552     StringCat (buf, "] ");
1553   }
1554   if (! StringHasNoText (genecontext.label)) {
1555     StringCat (buf, "[gene=");
1556     StringCat (buf, genecontext.label);
1557     StringCat (buf, "] ");
1558   }
1559   TrimSpacesAroundString (buf);
1560   FastaFileFunc (bsp, FASTA_DEFLINE, buf, sizeof (buf), (Pointer) fp);
1561   fflush (fp);
1562   SeqLocFastaStream (sfp->location, fp, STREAM_EXPAND_GAPS | STREAM_CORRECT_INVAL, 70, 0, 0);
1563   /*
1564   while (FastaSeqLine (spp, buf, 70, TRUE)) {
1565     FastaFileFunc (bsp, FASTA_SEQLINE, buf, sizeof (buf), (Pointer) fp);
1566   }
1567   SeqPortFree (spp);
1568   FastaFileFunc (bsp, FASTA_EOS, buf, sizeof (buf), (Pointer)fp);
1569   */
1570 }
1571 
FetchSequence(DoC d,Int2 item,Pointer ptr,FmtType format,Boolean do_fasta,Boolean do_cds,Boolean is_na)1572 static CharPtr FetchSequence (DoC d, Int2 item, Pointer ptr, FmtType format,
1573                               Boolean do_fasta, Boolean do_cds, Boolean is_na)
1574 
1575 {
1576   BioseqPtr    bsp;
1577   CharPtr      failed;
1578   FILE         *fp;
1579   Int4         flags = -1;
1580   Uint1        group_segs = 0;
1581   ErrSev       level;
1582   Boolean      master_style = FALSE;
1583   Boolean      okay = FALSE;
1584   Char         path [PATH_MAX];
1585   Int2         retcode;
1586   SeqEntryPtr  seqEntryPtr;
1587   SeqEntryPtr  sep;
1588   SummFormPtr  sfp;
1589   CharPtr      str;
1590   Int4         uid;
1591   CharPtr      currDbName;
1592 
1593   sfp = (SummFormPtr) GetObjectExtra (d);
1594   failed = SetDefaultFailureMessage (sfp, item, NULL);
1595   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
1596   if (item < 1) return failed;
1597   uid = sfp->uids [item - 1];
1598 
1599   currDbName = DBGetNameFromID (sfp->currDb);
1600   str = NULL;
1601 
1602   retcode = GetSequenceComplexity ();
1603   if ((seqEntryPtr = PubSeqSynchronousQuery (uid, retcode, flags)) == NULL) return failed;
1604 
1605   bsp = GetBioseqForUid (seqEntryPtr, uid);
1606   sep = SeqMgrGetSeqEntryForData (bsp);
1607   if (sep == NULL) {
1608     SeqEntryFree (seqEntryPtr);
1609     return failed;
1610   }
1611 
1612   if ((! do_fasta) && (! do_cds)) {
1613     LookupFarSeqIDs (seqEntryPtr, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE);
1614   }
1615 
1616   /*------------------------*/
1617   /* Store to temp file and */
1618   /* then read back in.     */
1619   /*------------------------*/
1620 
1621   str = NULL;
1622   TmpNam (path);
1623   fp = FileOpen (path, "w");
1624   if (fp != NULL) {
1625     level = ErrSetMessageLevel (SEV_MAX);
1626     if (do_fasta) {
1627       if (bsp->repr == Seq_repr_seg) {
1628         group_segs = 1;
1629         master_style = TRUE;
1630       } else if (bsp->repr == Seq_repr_delta) {
1631         group_segs = 3;
1632       }
1633       /*
1634       okay = SeqEntrysToFasta (seqEntryPtr, fp, is_na, group_segs);
1635       */
1636       if (is_na) {
1637         okay = (Boolean) SeqEntryFastaStream (sep, fp, STREAM_EXPAND_GAPS | STREAM_CORRECT_INVAL, 70, 0, 0, TRUE, FALSE, master_style);
1638       } else {
1639         okay = (Boolean) SeqEntryFastaStream (sep, fp, STREAM_EXPAND_GAPS | STREAM_CORRECT_INVAL, 70, 0, 0, FALSE, TRUE, master_style);
1640       }
1641     } else if (do_cds) {
1642       SeqMgrIndexFeatures (0, (Pointer) bsp);
1643       VisitFeaturesInSep (seqEntryPtr, (Pointer) fp, FormatCdsSeq);
1644       okay = TRUE;
1645     } else {
1646       okay = SeqEntryToGnbk (sep, NULL, format, ENTREZ_MODE, NORMAL_STYLE, 0,
1647                              LOOKUP_FAR_COMPONENTS | LOOKUP_FAR_LOCATIONS |
1648                              LOOKUP_FAR_PRODUCTS | LOOKUP_FAR_HISTORY,
1649                              0, NULL, fp);
1650     }
1651     if (okay) {
1652       FileClose (fp);
1653       str = FileToString (path);
1654     } else {
1655       FileClose (fp);
1656     }
1657     ErrSetMessageLevel (level);
1658   }
1659   FileRemove (path);
1660   SeqEntryFree (seqEntryPtr);
1661 
1662   if (str == NULL) return failed;
1663 
1664   MemFree (failed);
1665   return str;
1666 }
1667 
FetchGenBank(DoC d,Int2 item,Pointer ptr)1668 static CharPtr FetchGenBank (DoC d, Int2 item, Pointer ptr)
1669 
1670 {
1671   return FetchSequence (d, item, ptr, GENBANK_FMT, FALSE, FALSE, FALSE);
1672 }
1673 
FetchEmbl(DoC d,Int2 item,Pointer ptr)1674 static CharPtr FetchEmbl (DoC d, Int2 item, Pointer ptr)
1675 
1676 {
1677   return FetchSequence (d, item, ptr, EMBL_FMT, FALSE, FALSE, FALSE);
1678 }
1679 
FetchGenPept(DoC d,Int2 item,Pointer ptr)1680 static CharPtr FetchGenPept (DoC d, Int2 item, Pointer ptr)
1681 
1682 {
1683   return FetchSequence (d, item, ptr, GENPEPT_FMT, FALSE, FALSE, FALSE);
1684 }
1685 
FetchFastaNuc(DoC d,Int2 item,Pointer ptr)1686 static CharPtr FetchFastaNuc (DoC d, Int2 item, Pointer ptr)
1687 
1688 {
1689   return FetchSequence (d, item, ptr, (FmtType) 0, TRUE, FALSE, TRUE);
1690 }
1691 
FetchFastaProt(DoC d,Int2 item,Pointer ptr)1692 static CharPtr FetchFastaProt (DoC d, Int2 item, Pointer ptr)
1693 
1694 {
1695   return FetchSequence (d, item, ptr, (FmtType) 0, TRUE, FALSE, FALSE);
1696 }
1697 
FetchFastaCDS(DoC d,Int2 item,Pointer ptr)1698 static CharPtr FetchFastaCDS (DoC d, Int2 item, Pointer ptr)
1699 
1700 {
1701   return FetchSequence (d, item, ptr, (FmtType) 0, FALSE, TRUE, TRUE);
1702 }
1703 
1704 /*==================================================================*/
1705 /*                                                                  */
1706 /*  FetchPDB () -                                                   */
1707 /*                                                                  */
1708 /*==================================================================*/
1709 
FetchPDB(DoC d,Int2 item,Pointer ptr)1710 static CharPtr FetchPDB (DoC d, Int2 item, Pointer ptr)
1711 
1712 {
1713   BiostrucPtr     bsp = NULL;
1714   BiostrucSeqPtr  bsqp = NULL;
1715   CharPtr         failed;
1716   FILE            *fp;
1717   Char            path [PATH_MAX];
1718   PDNMS           pdnms;
1719   SummFormPtr     sfp;
1720   CharPtr         str;
1721   Int4            uid;
1722 
1723   str = NULL;
1724   sfp = (SummFormPtr) GetObjectExtra (d);
1725   failed = SetDefaultFailureMessage (sfp, item, NULL);
1726   if (sfp == NULL || sfp->uids == NULL || sfp->state == NULL) return failed;
1727   if (item < 1) return failed;
1728   uid = sfp->uids [item - 1];
1729   bsqp = StrucSynchronousQuery (uid);
1730   if (bsqp == NULL)  return failed;
1731   bsp = bsqp->structure;
1732   if (bsp == NULL) return failed;
1733 
1734   ClearStructures ();
1735   pdnms = MakeAModelstruc (bsp);
1736   if (pdnms == NULL) return failed;
1737 
1738   TmpNam (path);
1739   fp = FileOpen (path, "w");
1740   if (fp != NULL) {
1741     WriteStructSummary (pdnms, fp);
1742     fprintf (fp, "\n\n\n");
1743     WritePDBRemarks (pdnms, fp);
1744     FileClose (fp);
1745     str = FileToString (path);
1746   }
1747   FileRemove (path);
1748   FreeAModelstruc (pdnms);
1749 
1750   if (str == NULL) return failed;
1751 
1752   MemFree (failed);
1753   return str;
1754 }
1755 
1756 /*==================================================================*/
1757 /*                                                                  */
1758 /*  FetchLocalBioseq () -                                           */
1759 /*                                                                  */
1760 /*==================================================================*/
1761 
FetchLocalBioseq(DoC d,Int2 item,Pointer ptr)1762 static CharPtr FetchLocalBioseq (DoC d, Int2 item, Pointer ptr)
1763 
1764 {
1765   CharPtr       failed;
1766   FILE          *fp;
1767   Char          path [PATH_MAX];
1768   SummFormPtr   sfp;
1769   SimpleSeqPtr  ssp;
1770   CharPtr       str = NULL;
1771 
1772   /*--------------------------*/
1773   /* Check initial conditions */
1774   /*--------------------------*/
1775 
1776   sfp = (SummFormPtr) GetObjectExtra (d);
1777   failed = SetDefaultFailureMessage (sfp, item, NULL);
1778   if (sfp == NULL || sfp->simple == NULL || sfp->state == NULL) return failed;
1779   if (item < 1) return failed;
1780   ssp = sfp->simple [item - 1];
1781   if (ssp == NULL) return failed;
1782 
1783   TmpNam (path);
1784   fp = FileOpen (path, "w");
1785   if (fp != NULL) {
1786     if (SimpleSeqPrint (ssp, fp, TRUE)) {
1787       FileClose (fp);
1788       str = FileToString (path);
1789     } else
1790       FileClose (fp);
1791   }
1792   FileRemove (path);
1793 
1794   if (str == NULL) return failed;
1795 
1796   MemFree (failed);
1797   return str;
1798 }
1799 
1800 /*==================================================================*/
1801 /*                                                                  */
1802 /*  SetDocSumImportExportItems () -                                 */
1803 /*                                                                  */
1804 /*==================================================================*/
1805 
SetDocSumImportExportItems(SummFormPtr sfp)1806 static void SetDocSumImportExportItems (SummFormPtr sfp)
1807 
1808 {
1809   IteM          exportItm;
1810   IteM          importItm;
1811   CharPtr       dbName;
1812   CharPtr PNTR  labels = defaultRadios;
1813   Boolean       lastChoiceIsUidList = FALSE;
1814   Char          tmp [64];
1815   Int2          val;
1816 
1817   if (sfp == NULL)
1818     return;
1819 
1820   importItm = FindFormMenuItem ((BaseFormPtr) sfp, VIB_MSG_IMPORT);
1821   if (importItm != NULL)
1822     SafeSetTitle (importItm, "Import FASTA or Uid List...");
1823 
1824   exportItm = FindFormMenuItem ((BaseFormPtr) sfp, VIB_MSG_EXPORT);
1825   if (exportItm == NULL) return;
1826 
1827   sfp->label = medRadios [0];
1828   if (sfp->simple != NULL)
1829     sfp->label = localBioseqRadios [0];
1830   else if (sfp->currDb >= 0 && sfp->currDb < MAX_DBS) {
1831     dbName = DBGetNameFromID (sfp->currDb);
1832     if (StringICmp (dbName, "PubMed") == 0)
1833       labels = medRadios;
1834     else if (StringICmp (dbName, "Protein") == 0)
1835       labels = prtRadios;
1836     else if (StringICmp (dbName, "Nucleotide") == 0)
1837       labels = nucRadios;
1838     else if (StringICmp (dbName, "nuccore") == 0)
1839       labels = nucRadios;
1840     else if (StringICmp (dbName, "Structure") == 0)
1841       labels = strucRadios;
1842     else if (StringICmp (dbName, "Genome") == 0)
1843       labels = genRadios;
1844     else if (StringICmp (dbName, "Popset") == 0)
1845       labels = popsetRadios;
1846     else if (StringICmp (dbName, "OMIM") == 0)
1847       labels = omimRadios;
1848     else if (StringICmp (dbName, "Taxonomy") == 0)
1849       labels = taxonomyRadios;
1850     else if (StringICmp (dbName, "Books") == 0)
1851       labels = bookRadios;
1852     else if (StringICmp (dbName, "geo") == 0)
1853       labels = probeRadios;
1854     else if (StringICmp (dbName, "domains") == 0)
1855       labels = domainRadios;
1856     else if (StringICmp (dbName, "unists") == 0)
1857       labels = stsRadios;
1858     else if (StringICmp (dbName, "cdd") == 0)
1859       labels = cddRadios;
1860     else if (StringICmp (dbName, "snp") == 0)
1861       labels = snpRadios;
1862     else if (StringICmp (dbName, "journals") == 0)
1863       labels = journalsRadios;
1864     else if (StringICmp (dbName, "unigene") == 0)
1865       labels = unigeneRadios;
1866     else if (StringICmp (dbName, "PMC") == 0)
1867       labels = pmcRadios;
1868     else if (StringICmp (dbName, "ncbisearch") == 0)
1869       labels = ncbisearchRadios;
1870     else if (StringICmp (dbName, "mesh") == 0)
1871       labels = meshRadios;
1872     else if (StringICmp (dbName, "gene") == 0)
1873       labels = geneRadios;
1874     else
1875       labels = defaultRadios;
1876 
1877     val = GetValue (sfp->formatPopups [sfp->currDb]);
1878     if (val > 0) {
1879       sfp->label = labels [val - 1];
1880       if (labels [val] == NULL)
1881         lastChoiceIsUidList = TRUE;
1882     }
1883   }
1884   StringCpy (tmp, "Export ");
1885   StringCat (tmp, sfp->label);
1886   if (lastChoiceIsUidList)
1887     StringCat (tmp, " List");
1888   StringCat (tmp, "...");
1889   SafeSetTitle (exportItm, tmp);
1890 }
1891 
1892 /*==================================================================*/
1893 /*                                                                  */
1894 /*  Query_FetchNeighbors() - Gets UIDs for the neighbors of all the */
1895 /*                           currently selected documents.          */
1896 /*                                                                  */
1897 /*    Input :                                                       */
1898 /*       sfp->currDb           -- The database to link FROM         */
1899 /*       sfp->neighborDb       -- The database to link TO           */
1900 /*       sfp->uids             -- The list of ALL the current       */
1901 /*                                documents.                        */
1902 /*       sfp->numUids          -- Count of documents in sfp->uids   */
1903 /*       sfp->state [n].checked -- Flag to indicate which of the     */
1904 /*                                documents in sfp->uids are        */
1905 /*                                selected.                         */
1906 /*                                                                  */
1907 /*    Output :                                                      */
1908 /*       sfp->numNeighbors -- The number of neighbors found.        */
1909 /*       sfp->neighbors    -- The uids of the neighbors.            */
1910 /*                                                                  */
1911 /*==================================================================*/
1912 
Query_FetchNeighbors(SummFormPtr sfp,Int2 num)1913 static Boolean Query_FetchNeighbors (SummFormPtr sfp, Int2 num)
1914 
1915 {
1916   Int2                i;
1917   Int4Ptr             uids;
1918   Boolean             found;
1919   Entrez2RequestPtr   e2RequestPtr;
1920   Entrez2ReplyPtr     e2ReplyPtr;
1921   Entrez2LinkSetPtr   e2LinksPtr;
1922   CharPtr             currDbName;
1923   CharPtr             targetDbName;
1924   Entrez2InfoPtr      e2ip;
1925   Entrez2DbInfoPtr    e2db;
1926   Entrez2LinkInfoPtr  dbLinks;
1927 
1928   /*------------------*/
1929   /* Check conditions */
1930   /*------------------*/
1931 
1932   if (sfp == NULL) return FALSE;
1933 
1934   e2ip = Query_GetInfo ();
1935   if (e2ip == NULL) return FALSE;
1936 
1937   /*---------------------------------------*/
1938   /* Allocate memory for the selected UIDs */
1939   /*---------------------------------------*/
1940 
1941   uids = MemNew ((size_t) (num + 1) * sizeof (DocUid));
1942   if (uids == NULL) return FALSE;
1943 
1944   /*----------------------------------*/
1945   /* Determine the link type based on */
1946   /* the current (source) and the     */
1947   /* target db.                       */
1948   /*----------------------------------*/
1949 
1950   currDbName = DBGetNameFromID (sfp->currDb);
1951   targetDbName = DBGetNameFromID (sfp->neighborDb);
1952 
1953   found = FALSE;
1954   for (e2db = e2ip->db_info; e2db != NULL; e2db = e2db->next) {
1955     if (StringICmp (e2db->db_name, currDbName) == 0) {
1956       found = TRUE;
1957       break;
1958     }
1959   }
1960 
1961   if (! found) return FALSE;
1962 
1963   found = FALSE;
1964   for (dbLinks = e2db->links; dbLinks != NULL; dbLinks = dbLinks->next) {
1965     if (StringICmp (dbLinks->db_to, targetDbName) == 0) {
1966       found = TRUE;
1967       break;
1968     }
1969   }
1970 
1971   if (! found) return FALSE;
1972 
1973   /*----------------------*/
1974   /* Get the uids for the */
1975   /* selected items.      */
1976   /*----------------------*/
1977 
1978   num = 0;
1979   for (i = 0; i < sfp->numUids; i++) {
1980     if (sfp->state [i].checked) {
1981       uids [num] = sfp->uids [i];
1982       num++;
1983     }
1984   }
1985 
1986   /*----------------------------------------*/
1987   /* Create a link list request, send it to */
1988   /* the server, and parse the result.      */
1989   /*----------------------------------------*/
1990 
1991   e2RequestPtr = EntrezCreateGetLinksRequest (currDbName, 0, num, uids, NULL, dbLinks->link_name, MAX_UIDS, FALSE, TRUE);
1992   if (e2RequestPtr == NULL) return FALSE;
1993 
1994   if (ShowASN () == TRUE)
1995     DisplayEntrezRequest (e2RequestPtr);
1996 
1997   if ((e2ReplyPtr = SpecialEntrezSynchronousQuery (e2RequestPtr)) == NULL)
1998     return FALSE;
1999 
2000   if (ShowASN () == TRUE)
2001     DisplayEntrezReply (e2ReplyPtr);
2002 
2003   if ((e2LinksPtr = EntrezExtractLinksReply (e2ReplyPtr)) == NULL) return FALSE;
2004 
2005   sfp->numNeighbors = (Int2) e2LinksPtr->ids->num;
2006   sfp->neighbors = (Int4Ptr) BSMerge (e2LinksPtr->ids->uids, NULL);
2007 
2008   /*----------------------------------*/
2009   /* Clean up and return successfully */
2010   /*----------------------------------*/
2011 
2012   MemFree (uids);
2013   return TRUE;
2014 }
2015 
2016 /*==================================================================*/
2017 /*                                                                  */
2018 /*  RecalculateDocSum () -                                          */
2019 /*                                                                  */
2020 /*==================================================================*/
2021 
RecalculateDocSum(SummFormPtr sfp)2022 static void RecalculateDocSum (SummFormPtr sfp)
2023 
2024 {
2025   Int2    i;
2026   Int2    num;
2027   Int2    targetDb;
2028   Char    title [32];
2029   UIEnum  val;
2030 
2031   /*------------------*/
2032   /* Check conditions */
2033   /*------------------*/
2034 
2035   if (sfp == NULL) return;
2036 
2037   /*-------------------*/
2038   /* Get the target DB */
2039   /*-------------------*/
2040 
2041   if (GetEnumPopup (sfp->target, sfp->dbalist, &val)) {
2042     targetDb = (Int2) val;
2043   } else {
2044     targetDb = sfp->currDb;
2045   }
2046 
2047   /*-------------------------------------------*/
2048   /* If there's nothing to lookup, just return */
2049   /*-------------------------------------------*/
2050 
2051   if (sfp->uids == NULL || sfp->state == NULL) {
2052     if (targetDb == sfp->currDb)
2053       SafeSetTitle (sfp->retrieve, "Neighbor 0");
2054     else
2055       SafeSetTitle (sfp->retrieve, "Lookup 0");
2056     SafeDisable (sfp->retrieve);
2057     return;
2058   }
2059 
2060   sfp->neighbors = MemFree (sfp->neighbors);
2061   sfp->numNeighbors = 0;
2062   sfp->neighborDb = targetDb;
2063 
2064   /*----------------------------------*/
2065   /* FInd out how many, if any, items */
2066   /* are marked.                      */
2067   /*----------------------------------*/
2068 
2069   num = 0;
2070   for (i = 0; i < sfp->numUids; i++) {
2071     if (sfp->state [i].checked) {
2072       num++;
2073     }
2074   }
2075 
2076   /*----------------------------------------*/
2077   /* Update the refine and retrieve buttons */
2078   /*----------------------------------------*/
2079 
2080   if (sfp->retrieveMode == EVAL_MODE && sfp->usingDelay) {
2081     if (num == 0) {
2082       if (targetDb == sfp->currDb)
2083         SafeSetTitle (sfp->retrieve, "Neighbor 0");
2084       else
2085         SafeSetTitle (sfp->retrieve, "Lookup 0");
2086       SafeDisable (sfp->retrieve);
2087     } else {
2088       SafeSetTitle (sfp->retrieve, "Evaluate");
2089       SafeEnable (sfp->retrieve);
2090     }
2091     if (num == 0)
2092       num = sfp->numUids;
2093     sprintf (title, "Refine %d", (int) num);
2094     SafeSetTitle (sfp->refine, title);
2095     if (num > 0)
2096       SafeEnable (sfp->refine);
2097     else
2098       SafeDisable (sfp->refine);
2099     return;
2100   }
2101 
2102   /*------------------------------------------*/
2103   /* If there's any items to be queried, then */
2104   /* get a count and a list of UIDs for them. */
2105   /*------------------------------------------*/
2106 
2107   if (num > 0)
2108     Query_FetchNeighbors (sfp, num);
2109 
2110   /*--------------------------*/
2111   /* Update the button labels */
2112   /*--------------------------*/
2113 
2114   if (targetDb == sfp->currDb)
2115     sprintf (title, "Neighbor %d", (int) sfp->numNeighbors);
2116   else
2117     sprintf (title, "Lookup %d", (int) sfp->numNeighbors);
2118 
2119   SafeSetTitle (sfp->retrieve, title);
2120   if (sfp->numNeighbors > 0)
2121     SafeEnable (sfp->retrieve);
2122   else
2123     SafeDisable (sfp->retrieve);
2124 
2125   if (num == 0)
2126     num = sfp->numUids;
2127   sprintf (title, "Refine %d", (int) num);
2128   SafeSetTitle (sfp->refine, title);
2129   if (num > 0)
2130     SafeEnable (sfp->refine);
2131   else
2132     SafeDisable (sfp->refine);
2133 }
2134 
2135 /*==================================================================*/
2136 /*                                                                  */
2137 /*  RepopulateDocSum () -                                           */
2138 /*                                                                  */
2139 /*==================================================================*/
2140 
2141 static DocPrntProc defaultDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2142 static DocPrntProc mlDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchAbstract, FetchCitation, FetchMedline, FetchUid, NULL };
2143 static DocPrntProc aaDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchGenPept, FetchFastaProt, FetchUid, NULL };
2144 static DocPrntProc ntDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchGenBank, FetchEmbl, FetchFastaNuc, FetchFastaCDS, FetchUid, NULL };
2145 static DocPrntProc stDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchPDB, FetchUid, NULL };
2146 static DocPrntProc chDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2147 static DocPrntProc popsetDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2148 static DocPrntProc omimDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2149 static DocPrntProc taxonomyDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2150 static DocPrntProc bookDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2151 static DocPrntProc probeDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2152 static DocPrntProc domainDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2153 static DocPrntProc stsDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2154 static DocPrntProc cddDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2155 static DocPrntProc snpDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2156 static DocPrntProc journalsDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2157 static DocPrntProc unigeneDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2158 static DocPrntProc pmcDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2159 static DocPrntProc ncbisearchDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2160 static DocPrntProc meshDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2161 static DocPrntProc geneDocProcs [] = { Query_FetchDocSum, Query_FetchFields, FetchUid, NULL };
2162 
RepopulateDocSum(SummFormPtr sfp,Boolean needToReset)2163 static void RepopulateDocSum (SummFormPtr sfp, Boolean needToReset)
2164 
2165 {
2166   ColPtr               colFmt;
2167   CharPtr              dbName;
2168   DocDrawProc          ddp;
2169   Int2                 estLines;
2170   Int2                 firstLine;
2171   Int2                 firstShown;
2172   FonT                 font;
2173   MedlineViewProcsPtr  mvpp;
2174   DocPrntProc          retrieveProc;
2175   BaR                  sb;
2176   Int4                 startsAt;
2177   SeqViewProcsPtr      svpp;
2178   Int2                 val;
2179 
2180   /*------------------------*/
2181   /* Make sure that initial */
2182   /* conditions are valid   */
2183   /*------------------------*/
2184 
2185   if (sfp == NULL) return;
2186 
2187   /*---------------*/
2188   /*---------------*/
2189 
2190   WatchCursor ();
2191   SafeHide (sfp->docsum);
2192   Update ();
2193 
2194   /*----------------*/
2195   /*----------------*/
2196 
2197   if (! GetScrlParams4 (sfp->docsum, NULL, &firstShown, &firstLine)) {
2198     firstShown = 0;
2199     firstLine = 0;
2200   }
2201   sb = GetSlateVScrollBar ((SlatE) sfp->docsum);
2202   if (needToReset) {
2203     Reset (sfp->docsum);
2204     SetDocShade (sfp->docsum, NULL, NULL, NULL, NULL);
2205     SetDocCache (sfp->docsum, NULL, NULL, NULL);
2206   }
2207 
2208   /*----------------*/
2209   /*----------------*/
2210 
2211   dbName = DBGetNameFromID (sfp->currDb);
2212 
2213   retrieveProc = Query_FetchDocSum;
2214   ddp = DrawDocSum;
2215   colFmt = docsumColFmt;
2216   estLines = 3;
2217   font = sfp->docsumFont;
2218 
2219   if (sfp->simple != NULL) {
2220     retrieveProc = FetchLocalBioseq;
2221     ddp = DrawLocalSum;
2222     colFmt = textColFmt;
2223     svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
2224     if (svpp != NULL && svpp->displayFont != NULL)
2225       font = svpp->displayFont;
2226   }
2227 
2228   else if (sfp->currDb >= 0 && sfp->currDb < MAX_DBS) {
2229     val = GetValue (sfp->formatPopups [sfp->currDb]);
2230     if (val > 0) {
2231       if (val > 2) {
2232         ddp = DrawTextSum;
2233         colFmt = textColFmt;
2234         estLines = 30;
2235         if ((StringICmp (dbName, "PubMed") == 0) && (val == 5)) {
2236           mvpp = (MedlineViewProcsPtr)
2237             GetAppProperty ("MedlineDisplayForm");
2238           if (mvpp != NULL && mvpp->displayFont != NULL)
2239             font = mvpp->displayFont;
2240         } else if ((StringICmp (dbName, "Protein") == 0) ||
2241                    (StringICmp (dbName, "Nucleotide") == 0) ||
2242                    (StringICmp (dbName, "nuccore") == 0)) {
2243           svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
2244           if (svpp != NULL && svpp->displayFont != NULL)
2245             font = svpp->displayFont;
2246         }
2247       }
2248 
2249       if (StringICmp (dbName, "PubMed") == 0)
2250         retrieveProc = mlDocProcs [val - 1];
2251       else if (StringICmp (dbName, "Protein") == 0)
2252         retrieveProc = aaDocProcs [val - 1];
2253       else if (StringICmp (dbName, "Nucleotide") == 0)
2254         retrieveProc = ntDocProcs [val - 1];
2255       else if (StringICmp (dbName, "nuccore") == 0)
2256         retrieveProc = ntDocProcs [val - 1];
2257       else if (StringICmp (dbName, "Structure") == 0)
2258         retrieveProc = stDocProcs [val - 1];
2259       else if (StringICmp (dbName, "Genome") == 0)
2260         retrieveProc = chDocProcs [val - 1];
2261       else if (StringICmp (dbName, "Popset") == 0)
2262         retrieveProc = popsetDocProcs [val - 1];
2263       else if (StringICmp (dbName, "OMIM") == 0)
2264         retrieveProc = omimDocProcs [val - 1];
2265       else if (StringICmp (dbName, "Taxonomy") == 0)
2266         retrieveProc = taxonomyDocProcs [val - 1];
2267       else if (StringICmp (dbName, "Books") == 0)
2268         retrieveProc = bookDocProcs [val - 1];
2269       else if (StringICmp (dbName, "geo") == 0)
2270         retrieveProc = probeDocProcs [val - 1];
2271       else if (StringICmp (dbName, "domains") == 0)
2272         retrieveProc = domainDocProcs [val - 1];
2273       else if (StringICmp (dbName, "unists") == 0)
2274         retrieveProc = stsDocProcs [val - 1];
2275       else if (StringICmp (dbName, "cdd") == 0)
2276         retrieveProc = domainDocProcs [val - 1];
2277       else if (StringICmp (dbName, "snp") == 0)
2278         retrieveProc = snpDocProcs [val - 1];
2279       else if (StringICmp (dbName, "journals") == 0)
2280         retrieveProc = journalsDocProcs [val - 1];
2281       else if (StringICmp (dbName, "unigene") == 0)
2282         retrieveProc = unigeneDocProcs [val - 1];
2283       else if (StringICmp (dbName, "PMC") == 0)
2284         retrieveProc = pmcDocProcs [val - 1];
2285       else if (StringICmp (dbName, "ncbisearch") == 0)
2286         retrieveProc = ncbisearchDocProcs [val - 1];
2287       else if (StringICmp (dbName, "mesh") == 0)
2288         retrieveProc = meshDocProcs [val - 1];
2289       else if (StringICmp (dbName, "gene") == 0)
2290         retrieveProc = geneDocProcs [val - 1];
2291       else
2292         retrieveProc = defaultDocProcs [val - 1];
2293 
2294     }
2295   }
2296 
2297   /*--------------------------------*/
2298   /* Retrieve the docs and put them */
2299   /* into the docsum window.        */
2300   /*--------------------------------*/
2301 
2302   MemSet ((Pointer) sfp->formatted, 0, sizeof (Boolean) * (size_t) sfp->numUids);
2303 
2304   BulkAppendItem (sfp->docsum, sfp->numUids, retrieveProc, estLines, &docsumParFmt, colFmt, font);
2305 
2306   /*-------------------------------------*/
2307   /* Draw and display the document panel */
2308   /*-------------------------------------*/
2309 
2310   SetDocShade (sfp->docsum, ddp, NULL, NULL, NULL);
2311   SetDocCache (sfp->docsum, StdPutDocCache, StdGetDocCache, StdResetDocCache);
2312 
2313   AdjustDocScroll (sfp->docsum);
2314   GetItemParams4 (sfp->docsum, firstShown, &startsAt, NULL, NULL, NULL, NULL);
2315   CorrectBarValue (sb, startsAt + firstLine);
2316   ResetClip ();
2317   SafeShow (sfp->docsum);
2318   ArrowCursor ();
2319   Update ();
2320 }
2321 
2322 /*==================================================================*/
2323 /*                                                                  */
2324 /*  ChangeTarget () -                                               */
2325 /*                                                                  */
2326 /*==================================================================*/
2327 
ChangeTarget(PopuP p)2328 static void ChangeTarget (PopuP p)
2329 
2330 {
2331   SummFormPtr  sfp;
2332 
2333   sfp = (SummFormPtr) GetObjectExtra (p);
2334   if (sfp == NULL) return;
2335   sfp->retrieveMode = EVAL_MODE;
2336   RecalculateDocSum (sfp);
2337 }
2338 
2339 /*==================================================================*/
2340 /*                                                                  */
2341 /*  ChangeFormat () -                                               */
2342 /*                                                                  */
2343 /*==================================================================*/
2344 
ChangeFormat(PopuP p)2345 static void ChangeFormat (PopuP p)
2346 
2347 {
2348   SummFormPtr  sfp;
2349 
2350   sfp = (SummFormPtr) GetObjectExtra (p);
2351   if (sfp == NULL) return;
2352   RepopulateDocSum (sfp, TRUE);
2353   SetDocSumImportExportItems (sfp);
2354 }
2355 
2356 /*==================================================================*/
2357 /*                                                                  */
2358 /*  ResizeDocSumForm () -                                            */
2359 /*                                                                  */
2360 /*==================================================================*/
2361 
ResizeDocSumForm(WindoW w)2362 static void ResizeDocSumForm (WindoW w)
2363 
2364 {
2365   Int2         diff;
2366   Int2         gap;
2367   Int2         height;
2368   Int2         quarter;
2369   RecT         r;
2370   Int2         remaining;
2371   RecT         s;
2372   SummFormPtr  sfp;
2373   RecT         t;
2374   Int2         width;
2375 
2376   sfp = (SummFormPtr) GetObjectExtra (w);
2377   if (sfp == NULL) return;
2378   WatchCursor ();
2379   ObjectRect (w, &r);
2380   width = r.right - r.left;
2381   height = r.bottom - r.top;
2382   GetPosition (sfp->docsum, &s);
2383   GetPosition (sfp->controls, &t);
2384   diff = t.bottom - t.top;
2385   gap = t.top - s.bottom;
2386   t.bottom = height - s.left;
2387   t.top = t.bottom - diff;
2388   s.right = width - s.left;
2389   s.bottom = t.top - gap;
2390   SafeHide (sfp->controls);
2391   SetPosition (sfp->controls, &t);
2392   AdjustPrnt (sfp->controls, &t, FALSE);
2393   SetPosition (sfp->docsum, &s);
2394   AdjustPrnt (sfp->docsum, &s, FALSE);
2395   ObjectRect (sfp->docsum, &s);
2396   InsetRect (&s, 4, 4);
2397   docsumColFmt [0].pixInset = 6 * stdCharWidth;
2398   remaining = s.right - s.left - 6 * stdCharWidth;
2399   quarter = remaining / 4;
2400   docsumColFmt [0].pixWidth = quarter + 6 * stdCharWidth;
2401   docsumColFmt [1].pixWidth = remaining - quarter;
2402   SafeShow (sfp->controls);
2403   RepopulateDocSum (sfp, TRUE);
2404   ArrowCursor ();
2405   Update ();
2406 }
2407 
2408 /*==================================================================*/
2409 /*                                                                  */
2410 /*  CleanupEntrezDocSumForm () -                                    */
2411 /*                                                                  */
2412 /*==================================================================*/
2413 
CleanupEntrezDocSumForm(GraphiC g,VoidPtr data)2414 static void CleanupEntrezDocSumForm (GraphiC g, VoidPtr data)
2415 
2416 {
2417   Int2         j;
2418   SummFormPtr  sfp;
2419 
2420   sfp = (SummFormPtr) data;
2421   if (sfp != NULL) {
2422     MemFree (sfp->uids);
2423     MemFree (sfp->formatted);
2424     if (sfp->simple != NULL) {
2425       for (j = 0; j < sfp->numUids; j++) {
2426         SimpleSeqFree (sfp->simple [j]);
2427       }
2428       sfp->simple = MemFree (sfp->simple);
2429     }
2430     MemFree (sfp->state);
2431     MemFree (sfp->neighbors);
2432     FileRemove (sfp->historyFile);
2433     MemFree (sfp->historyFile);
2434     MemFree (sfp->historyOffsets);
2435     if (sfp->dbalist != NULL) {
2436       for (j = 0; sfp->dbalist [j].name != NULL; j++) {
2437         MemFree (sfp->dbalist [j].name);
2438       }
2439     }
2440     MemFree (sfp->dbalist);
2441     Entrez2DocsumListFree (sfp->tempE2DLP);
2442   }
2443   StdCleanupFormProc (g, data);
2444 }
2445 
2446 /*==================================================================*/
2447 /*                                                                  */
2448 /*  ClickDocSum () -                                                */
2449 /*                                                                  */
2450 /*==================================================================*/
2451 
ClickDocSum(DoC d,PoinT pt)2452 static void ClickDocSum (DoC d, PoinT pt)
2453 
2454 {
2455   Int2         col;
2456   Int2         item;
2457   Int2         row;
2458   SummFormPtr  sfp;
2459 
2460   sfp = (SummFormPtr) GetObjectExtra (d);
2461   if (sfp == NULL) return;
2462   MapDocPoint (d, pt, &item, &row, &col, NULL);
2463   sfp->dsClickItem = item;
2464   sfp->dsClickRow = row;
2465   sfp->dsClickCol = col;
2466   sfp->wasDoubleClick = dblClick;
2467 }
2468 
2469 /*==================================================================*/
2470 /*                                                                  */
2471 /*  GetCheckedUids () -                                             */
2472 /*                                                                  */
2473 /*==================================================================*/
2474 
GetCheckedUids(SummFormPtr sfp,Int2Ptr nump)2475 static Int4Ptr GetCheckedUids (SummFormPtr sfp, Int2Ptr nump)
2476 
2477 {
2478   Int2     i;
2479   Int2     num;
2480   Int4Ptr  uids;
2481 
2482   if (sfp == NULL || nump == NULL) return NULL;
2483   uids = NULL;
2484   num = 0;
2485   for (i = 0; i < sfp->numUids; i++) {
2486     if (sfp->state [i].checked) {
2487       num++;
2488     }
2489   }
2490   if (num > 0) {
2491     uids = MemNew ((size_t) (num + 1) * sizeof (DocUid));
2492     if (uids != NULL) {
2493       num = 0;
2494       for (i = 0; i < sfp->numUids; i++) {
2495         if (sfp->state [i].checked) {
2496           uids [num] = sfp->uids [i];
2497           num++;
2498         }
2499       }
2500     }
2501   }
2502   if (nump != NULL) {
2503     *nump = num;
2504   }
2505   return uids;
2506 }
2507 
2508 /*==================================================================*/
2509 /*                                                                  */
2510 /*  LaunchMedlineViewer () -                                        */
2511 /*                                                                  */
2512 /*==================================================================*/
2513 
LaunchMedlineViewer(Int4 uid)2514 static void LaunchMedlineViewer (Int4 uid)
2515 
2516 {
2517   Pointer          dataptr;
2518   Uint2            datatype;
2519   Uint2            entityID;
2520   Int2             handled;
2521   MedlineEntryPtr  mep;
2522   PubmedEntryPtr   pep;
2523 
2524   WatchCursor ();
2525   Update ();
2526   pep = PubMedSynchronousQuery (uid);
2527   if (pep == NULL) {
2528     ArrowCursor ();
2529     Update ();
2530     Message (MSG_OK, "Unable to find this record in the database.");
2531     return;
2532   }
2533   datatype = OBJ_MEDLINE_ENTRY;
2534   mep = (MedlineEntryPtr) pep->medent;
2535   if (mep != NULL && mep->uid == 0) {
2536     mep->uid = uid;
2537   }
2538   dataptr = (Pointer) mep;
2539   entityID = ObjMgrRegister (datatype, dataptr);
2540   if (dataptr == NULL || entityID == 0) {
2541     ArrowCursor ();
2542     Update ();
2543     Message (MSG_OK, "Unable to find this record in the database.");
2544     return;
2545   }
2546   handled = GatherProcLaunch (OMPROC_VIEW, FALSE, entityID, 1, OBJ_MEDLINE_ENTRY, 0, 0, OBJ_MEDLINE_ENTRY, 0);
2547   ArrowCursor ();
2548   if (handled != OM_MSG_RET_DONE || handled == OM_MSG_RET_NOPROC) {
2549     Message (MSG_ERROR, "Unable to launch viewer.");
2550     PubmedEntryFree (pep);
2551   } else {
2552     ObjMgrSetOptions (OM_OPT_FREE_IF_NO_VIEW, entityID);
2553   }
2554 }
2555 
2556 /*==================================================================*/
2557 /*                                                                  */
2558 /*  BioseqLockByGi () -                                             */
2559 /*                                                                  */
2560 /*==================================================================*/
2561 
BioseqLockByGi(Int4 uid)2562 static BioseqPtr BioseqLockByGi (Int4 uid)
2563 
2564 {
2565   ValNode  vn;
2566 
2567   if (uid <= 0) return NULL;
2568   vn.choice = SEQID_GI;
2569   vn.data.intvalue = uid;
2570   return BioseqLockById (&vn);
2571 }
2572 
2573 /*==================================================================*/
2574 /*                                                                  */
2575 /*  AddBlastAlignment () -                                          */
2576 /*                                                                  */
2577 /*==================================================================*/
2578 
AddBlastAlignment(Int4 uid,Int2 numAlign,Int4Ptr alignuids,Uint2 entityID,SeqEntryPtr sep,BioseqPtr subject)2579 static void AddBlastAlignment (Int4 uid, Int2 numAlign, Int4Ptr alignuids, Uint2 entityID, SeqEntryPtr sep, BioseqPtr subject)
2580 
2581 {
2582   Uint1                align_type = 0;
2583   BioseqPtr            bsp;
2584   BioseqSetPtr         bssp;
2585   SeqAnnotPtr          curr;
2586   Int2                 i;
2587   BLAST_OptionsBlkPtr  options = NULL;
2588   SeqAlignPtr          prev;
2589   CharPtr              program_name = NULL;
2590   BioseqPtr            query;
2591   SeqAlignPtr          salp;
2592   SeqAnnotPtr          sap;
2593   SeqAnnotPtr PNTR     sapp;
2594   BlastSearchBlkPtr    search;
2595 
2596   if (sep == NULL || numAlign == 0 || alignuids == NULL) return;
2597   sap = NULL;
2598   salp = NULL;
2599   if (subject == NULL)
2600     return;
2601   if (ISA_na (subject->mol)) {
2602     align_type = 1;
2603     program_name = "blastn";
2604     options = BLASTOptionNew (program_name, TRUE);
2605     if (options != NULL) {
2606       options->gapped_calculation = TRUE;
2607       options->db_length = 100000000;
2608 #ifdef WIN16
2609       options->wordsize = 10;
2610 #else
2611       options->wordsize = 12;
2612 #endif
2613     }
2614   } else if (ISA_aa (subject->mol)) {
2615     align_type = 2;
2616     program_name = "blastp";
2617     options = BLASTOptionNew (program_name, TRUE);
2618     if (options != NULL) {
2619       options->gapped_calculation = TRUE;
2620       options->db_length = 20000000;
2621       options->threshold_second = 12;
2622     }
2623   } else
2624     return;
2625   search = BLASTSetUpSearch (subject, program_name, 0, 0, NULL, options, NULL);
2626 
2627   for (i = 0; i < numAlign; i++) {
2628     if (alignuids [i] != uid) {
2629       query = BioseqLockByGi (alignuids [i]);
2630       if (query != NULL) {
2631         salp = BlastSequencesOnTheFly (search, query);
2632         BioseqUnlock (query);
2633         if (salp != NULL) {
2634           if (sap == NULL) {
2635             sap = SeqAnnotNew ();
2636             if (sap != NULL) {
2637               sap->type = 2;
2638             }
2639           }
2640           if (sap != NULL) {
2641             if (sap->data != NULL) {
2642               prev = sap->data;
2643               while (prev->next != NULL) {
2644                 prev = prev->next;
2645               }
2646               prev->next = salp;
2647             } else {
2648               sap->data = (Pointer) salp;
2649             }
2650           }
2651         }
2652       }
2653     }
2654   }
2655   BLASTOptionDelete (options);
2656   BlastSearchBlkDestruct (search);
2657 
2658   if (sap == NULL) return;
2659 
2660   AddAlignInfoToSeqAnnot (sap, align_type);
2661   /*
2662   ObjMgrRegister (OBJ_SEQANNOT, (Pointer) sap);
2663   */
2664   sapp = NULL;
2665   if (IS_Bioseq (sep)) {
2666     bsp = (BioseqPtr) sep->data.ptrvalue;
2667     sapp = &(bsp->annot);
2668   } else if (IS_Bioseq_set (sep)) {
2669     bssp = (BioseqSetPtr) sep->data.ptrvalue;
2670     sapp = &(bssp->annot);
2671   }
2672   if (sapp != NULL) {
2673     if (*sapp != NULL) {
2674       curr = *sapp;
2675       while (curr->next != NULL) {
2676         curr = curr->next;
2677       }
2678       curr->next = sap;
2679     } else {
2680       *sapp = sap;
2681     }
2682   }
2683 }
2684 
2685 /*==================================================================*/
2686 /*                                                                  */
2687 /*  LaunchSequenceViewer () -                                       */
2688 /*                                                                  */
2689 /*==================================================================*/
2690 
LaunchSequenceViewer(Int4 uid,Int2 numAlign,Int4Ptr alignuids,CharPtr dbName)2691 static void LaunchSequenceViewer (Int4 uid, Int2 numAlign, Int4Ptr alignuids, CharPtr dbName)
2692 
2693 {
2694   BioseqPtr          bsp;
2695   Entrez2GlobalsPtr  egp;
2696   Uint2              entityID;
2697   Int4               flags = -1;
2698   Int2               handled;
2699   Uint4              itemID;
2700   Int2               retcode;
2701   SeqEntryPtr        seqEntryPtr;
2702   ValNode            vn;
2703 
2704   WatchCursor ();
2705   Update ();
2706   retcode = GetSequenceComplexity ();
2707   seqEntryPtr = PubSeqSynchronousQuery (uid, retcode, flags);
2708   if (seqEntryPtr == NULL) {
2709     ArrowCursor ();
2710     Update ();
2711     Message (MSG_OK, "Unable to find this record in the database.");
2712     return;
2713   }
2714   entityID = BioseqFindEntityByGi (uid, &itemID);
2715   if (entityID == 0 || itemID == 0) {
2716     SeqEntryFree (seqEntryPtr);
2717     ArrowCursor ();
2718     Update ();
2719     return;
2720   }
2721 
2722   MemSet ((Pointer) &vn, 0, sizeof (ValNode));
2723   vn.choice = SEQID_GI;
2724   vn.data.intvalue = uid;
2725   bsp = BioseqFind (&vn);
2726   if (bsp == NULL) {
2727     ArrowCursor ();
2728     Update ();
2729     Message (MSG_OK, "Unable to find this record in memory.");
2730     return;
2731   }
2732 
2733   /*
2734   LookupFarSeqIDs (seqEntryPtr, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
2735   */
2736 
2737   egp = (Entrez2GlobalsPtr) GetAppProperty ("Entrez2Globals");
2738   if (egp != NULL) {
2739     SeqEntryPtr   sep;
2740 
2741     if (GetStatus (egp->alignWithChecked)) {
2742       sep = GetTopSeqEntryForEntityID (entityID);
2743       AddBlastAlignment (uid, numAlign, alignuids, entityID, sep, bsp);
2744     }
2745   }
2746 
2747   handled = GatherProcLaunch (OMPROC_VIEW, FALSE, entityID, itemID, OBJ_BIOSEQ, 0, 0, OBJ_BIOSEQ, 0);
2748   ArrowCursor ();
2749   if (handled != OM_MSG_RET_DONE || handled == OM_MSG_RET_NOPROC) {
2750     Message (MSG_ERROR, "Unable to launch viewer.");
2751     SeqEntryFree (seqEntryPtr);
2752   } else {
2753     ObjMgrSetOptions (OM_OPT_FREE_IF_NO_VIEW, entityID);
2754   }
2755 }
2756 
2757 /*==================================================================*/
2758 /*                                                                  */
2759 /*  LaunchSequin () -                                               */
2760 /*                                                                  */
2761 /*==================================================================*/
2762 
LaunchSequin(Int4 uid,Int2 numAlign,Int4Ptr alignuids,CharPtr dbName)2763 static void LaunchSequin (Int4 uid, Int2 numAlign, Int4Ptr alignuids, CharPtr dbName)
2764 
2765 {
2766   AsnIoPtr           aip;
2767   BioseqPtr          bsp;
2768   Entrez2GlobalsPtr  egp;
2769   Uint2              entityID;
2770   Int4               flags = -1;
2771   Uint4              itemID;
2772   Char               path [PATH_MAX];
2773   Int2               retcode;
2774   SeqEntryPtr        seqEntryPtr;
2775   ValNode            vn;
2776 #ifdef WIN_MOTIF
2777   Char               cmmd [PATH_MAX];
2778 #endif
2779 
2780   WatchCursor ();
2781   Update ();
2782   retcode = GetSequenceComplexity ();
2783   seqEntryPtr = PubSeqSynchronousQuery (uid, retcode, flags);
2784   if (seqEntryPtr == NULL) {
2785     ArrowCursor ();
2786     Update ();
2787     Message (MSG_OK, "Unable to find this record in the database.");
2788     return;
2789   }
2790   entityID = BioseqFindEntityByGi (uid, &itemID);
2791   if (entityID == 0 || itemID == 0) {
2792     SeqEntryFree (seqEntryPtr);
2793     ArrowCursor ();
2794     Update ();
2795     return;
2796   }
2797 
2798   MemSet ((Pointer) &vn, 0, sizeof (ValNode));
2799   vn.choice = SEQID_GI;
2800   vn.data.intvalue = uid;
2801   bsp = BioseqFind (&vn);
2802   if (bsp == NULL) {
2803     ArrowCursor ();
2804     Update ();
2805     Message (MSG_OK, "Unable to find this record in memory.");
2806     return;
2807   }
2808 
2809   egp = (Entrez2GlobalsPtr) GetAppProperty ("Entrez2Globals");
2810   if (egp != NULL) {
2811     SeqEntryPtr   sep;
2812 
2813     if (GetStatus (egp->alignWithChecked)) {
2814       sep = GetTopSeqEntryForEntityID (entityID);
2815       AddBlastAlignment (uid, numAlign, alignuids, entityID, sep, bsp);
2816     }
2817   }
2818 
2819   TmpNam (path);
2820   aip = AsnIoOpen (path, "w");
2821   if (aip == NULL) {
2822     ArrowCursor ();
2823     FileRemove (path);
2824     return;
2825   }
2826 
2827   SeqEntryAsnWrite (seqEntryPtr, aip, NULL);
2828   AsnIoClose (aip);
2829 
2830 #ifdef WIN_MAC
2831   Nlm_SendOpenDocAppleEvent (path, "SEQN");
2832 #endif
2833 #ifdef WIN_MSWIN
2834   Nlm_MSWin_OpenApplication ("sequin.exe", path);
2835 #endif
2836 #ifdef WIN_MOTIF
2837   sprintf (cmmd, "sequin -x < %s &", path);
2838   system (cmmd);
2839 #endif
2840 
2841   ArrowCursor ();
2842 }
2843 
2844 /*==================================================================*/
2845 /*                                                                  */
2846 /*  LaunchStructureViewer () -                                      */
2847 /*                                                                  */
2848 /*==================================================================*/
2849 
GetBiostrucComplexity(void)2850 static Int4 GetBiostrucComplexity (void)
2851 
2852 {
2853   Int4               complexity = ALLMDL;
2854   Entrez2GlobalsPtr  egp;
2855   Int2               val;
2856 
2857   egp = (Entrez2GlobalsPtr) GetAppProperty ("Entrez2Globals");
2858   if (egp == NULL) return complexity;
2859   val = GetValue (egp->strucComplex);
2860   switch (val) {
2861     case 1:
2862       complexity = ONECOORDATOM;
2863       break;
2864     case 2:
2865       complexity = ONECOORDRES;
2866       break;
2867     case 3:
2868       complexity = ALLMDL;
2869       break;
2870     case 4:
2871       complexity = VECMODEL;
2872       break;
2873     case 5:
2874       complexity = BSEVERYTHING;
2875       break;
2876     default:
2877       complexity = ONECOORDATOM;
2878       break;
2879   }
2880   return complexity;
2881 }
2882 
GetBiostrucMaxModels(void)2883 static Int4 GetBiostrucMaxModels (void)
2884 
2885 {
2886   Entrez2GlobalsPtr  egp;
2887   Int4               maxModels = INT4_MAX;
2888   Int2               val;
2889 
2890   egp = (Entrez2GlobalsPtr) GetAppProperty ("Entrez2Globals");
2891   if (egp == NULL) return maxModels;
2892   val = GetValue (egp->strucModels);
2893   switch (val) {
2894     case 1:
2895       maxModels = 1;
2896       break;
2897     case 2:
2898       maxModels = 2;
2899       break;
2900     case 3:
2901       maxModels = 5;
2902       break;
2903     case 4:
2904       maxModels = 10;
2905       break;
2906     case 5:
2907       maxModels = 15;
2908       break;
2909     case 6:
2910       maxModels = 20;
2911       break;
2912     case 7:
2913       maxModels = MAX_MDLNO;
2914       break;
2915     default:
2916       maxModels = 1;
2917       break;
2918   }
2919   return maxModels;
2920 }
2921 
LaunchStructureViewer(Int4 uid)2922 static void LaunchStructureViewer (Int4 uid)
2923 
2924 {
2925 #if defined(WIN16)
2926   Message (MSG_OK, "Structure views not supported on this platform.");
2927 #else
2928   AsnIoPtr        aip;
2929   BiostrucSeqPtr  bsqp = NULL;
2930   NcbiMimeAsn1    mime;
2931   Char            path [PATH_MAX];
2932 
2933 #ifdef WIN_MOTIF
2934   Char            cmmd [PATH_MAX];
2935 #endif
2936 #ifdef WIN_MSWIN
2937   Char            prog [PATH_MAX];
2938 #endif
2939 
2940   WatchCursor ();
2941   Update ();
2942   bsqp = StrucSynchronousQuery (uid);
2943   if (bsqp == NULL) {
2944     ArrowCursor ();
2945     Update ();
2946     Message (MSG_OK, "Unable to find this record in the database.");
2947     return;
2948   }
2949 
2950   TmpNam (path);
2951   aip = AsnIoOpen (path, "w");
2952 
2953   MemSet ((Pointer) &mime, 0, sizeof (NcbiMimeAsn1));
2954   mime.choice = NcbiMimeAsn1_strucseq;
2955   mime.data.ptrvalue = bsqp;
2956   mime.next = NULL;
2957 
2958   NcbiMimeAsn1AsnWrite (&mime, aip, NULL);
2959   AsnIoClose (aip);
2960 
2961   BiostrucSeqFree (bsqp);
2962 
2963   /* Cn3D expects Ncbi-mime-asn1, not Biostruc or BiostrucSeq */
2964 
2965 #ifdef WIN_MAC
2966   Nlm_SendOpenDocAppleEvent (path, "Cn3D");
2967 #endif
2968 #ifdef WIN_MSWIN
2969   Nlm_GetExecPath ("valfile", prog, sizeof (prog));
2970   Nlm_MSWin_OpenApplication (prog, path);
2971 #endif
2972 #ifdef WIN_MOTIF
2973   /*
2974    argv   [0] = path;
2975    argv   [1] = NULL;
2976    if (! Execv ("Cn3D", argv)) {
2977      Message (MSG_POST, "Unable to launch Cn3D");
2978    }
2979   */
2980   sprintf (cmmd, "Cn3D %s &", path);
2981   system (cmmd);
2982 #endif
2983 
2984   ArrowCursor ();
2985 #endif
2986 }
2987 
2988 /*==================================================================*/
2989 /*                                                                  */
2990 /*  LaunchXXXASN () -                                               */
2991 /*                                                                  */
2992 /*==================================================================*/
2993 
LaunchMedlineASN(Int4 uid)2994 static void LaunchMedlineASN (Int4 uid)
2995 
2996 {
2997   AsnIoPtr        aip;
2998   Char            path [PATH_MAX];
2999   PubmedEntryPtr  pep;
3000 
3001   WatchCursor ();
3002   Update ();
3003   pep = PubMedSynchronousQuery (uid);
3004   if (pep == NULL) {
3005     ArrowCursor ();
3006     Update ();
3007     Message (MSG_OK, "Unable to find this record in the database.");
3008     return;
3009   }
3010   TmpNam (path);
3011   aip = AsnIoOpen (path, "w");
3012   if (aip != NULL) {
3013     PubmedEntryAsnWrite (pep, aip, NULL);
3014     AsnIoClose (aip);
3015     LaunchGeneralTextViewer (path, "PubMed ASN.1");
3016   }
3017   FileRemove (path);
3018   PubmedEntryFree (pep);
3019   ArrowCursor ();
3020 }
3021 
LaunchSequenceASN(Int4 uid)3022 static void LaunchSequenceASN (Int4 uid)
3023 
3024 {
3025   AsnIoPtr     aip;
3026   Int4         flags = -1;
3027   Char         path [PATH_MAX];
3028   Int2         retcode;
3029   SeqEntryPtr  seqEntryPtr;
3030 
3031   WatchCursor ();
3032   Update ();
3033   retcode = GetSequenceComplexity ();
3034   seqEntryPtr = PubSeqSynchronousQuery (uid, retcode, flags);
3035   if (seqEntryPtr == NULL) {
3036     ArrowCursor ();
3037     Update ();
3038     Message (MSG_OK, "Unable to find this record in the database.");
3039     return;
3040   }
3041   TmpNam (path);
3042   aip = AsnIoOpen (path, "w");
3043   if (aip != NULL) {
3044     SeqEntryAsnWrite (seqEntryPtr, aip, NULL);
3045     AsnIoClose (aip);
3046     LaunchGeneralTextViewer (path, "Sequence ASN.1");
3047   }
3048   FileRemove (path);
3049   SeqEntryFree (seqEntryPtr);
3050   ArrowCursor ();
3051 }
3052 
LaunchStructureASN(Int4 uid)3053 static void LaunchStructureASN (Int4 uid)
3054 
3055 {
3056   AsnIoPtr        aip;
3057   BiostrucSeqPtr  bsqp = NULL;
3058   Char            path [PATH_MAX];
3059 
3060   WatchCursor ();
3061   Update ();
3062   bsqp = StrucSynchronousQuery (uid);
3063   if (bsqp == NULL) {
3064     ArrowCursor ();
3065     Update ();
3066     Message (MSG_OK, "Unable to find this record in the database.");
3067     return;
3068   }
3069   TmpNam (path);
3070   aip = AsnIoOpen (path, "w");
3071   if (aip != NULL) {
3072     BiostrucSeqAsnWrite (bsqp, aip, NULL);
3073     AsnIoClose (aip);
3074     LaunchGeneralTextViewer (path, "Structure ASN.1");
3075   }
3076   FileRemove (path);
3077   BiostrucSeqFree (bsqp);
3078   ArrowCursor ();
3079 }
3080 
LaunchMimASN(Int4 uid)3081 static void LaunchMimASN (Int4 uid)
3082 
3083 {
3084   AsnIoPtr     aip;
3085   MimEntryPtr  mep;
3086   Char         path [PATH_MAX];
3087 
3088   WatchCursor ();
3089   Update ();
3090   mep = MimSynchronousQuery (uid);
3091   if (mep == NULL) {
3092     ArrowCursor ();
3093     Update ();
3094     Message (MSG_OK, "Unable to find this record in the database.");
3095     return;
3096   }
3097   TmpNam (path);
3098   aip = AsnIoOpen (path, "w");
3099   if (aip != NULL) {
3100     MimEntryAsnWrite (mep, aip, NULL);
3101     AsnIoClose (aip);
3102     LaunchGeneralTextViewer (path, "MIM ASN.1");
3103   }
3104   FileRemove (path);
3105   MimEntryFree (mep);
3106   ArrowCursor ();
3107 }
3108 
3109 /*==================================================================*/
3110 /*                                                                  */
3111 /*  LaunchRecViewer () -                                            */
3112 /*                                                                  */
3113 /*==================================================================*/
3114 
LaunchRecViewer(ForM f,Int4 uid,Int2 numAlign,Int4Ptr alignuids,Int2 db,Int2 launchType)3115 NLM_EXTERN void LaunchRecViewer (ForM f, Int4 uid, Int2 numAlign, Int4Ptr alignuids, Int2 db, Int2 launchType)
3116 
3117 {
3118   CharPtr   dbName;
3119   Char      id [41];
3120   SeqIdPtr  sip;
3121 
3122   if (uid == 0) return;
3123 
3124   if (db >= 0 && db < MAX_DBS) {
3125     SeqEntrySetScope (NULL);
3126     dbName = DBGetNameFromID (db);
3127     if (StringICmp (dbName, "PubMed") == 0) {
3128       if (launchType == 1) {
3129         LaunchMedlineViewer (uid);
3130       } else if (launchType == 2) {
3131         LaunchEntrezURL ("PubMed", uid, "Abstract");
3132       } else if (launchType == 3) {
3133         LaunchMedlineASN (uid);
3134       }
3135     } else if (StringICmp (dbName, "Protein") == 0) {
3136       if (launchType == 1) {
3137         LaunchSequenceViewer (uid, numAlign, alignuids, dbName);
3138       } else if (launchType == 2) {
3139         LaunchSequin (uid, numAlign, alignuids, dbName);
3140       } else if (launchType == 3) {
3141         LaunchEntrezURL ("Protein", uid, "GenPept");
3142       } else if (launchType == 4) {
3143         LaunchSequenceASN (uid);
3144       }
3145     } else if (StringICmp (dbName, "Nucleotide") == 0 ||
3146                StringICmp (dbName, "nuccore") == 0) {
3147       if (launchType == 1) {
3148         LaunchSequenceViewer (uid, numAlign, alignuids, dbName);
3149       } else if (launchType == 2) {
3150         LaunchSequin (uid, numAlign, alignuids, dbName);
3151       } else if (launchType == 3) {
3152         LaunchEntrezURL ("Nucleotide", uid, "GenBank");
3153       } else if (launchType == 4) {
3154         LaunchSequenceASN (uid);
3155       }
3156     } else if (StringICmp (dbName, "Structure") == 0) {
3157       if (launchType == 1) {
3158         LaunchStructureViewer (uid);
3159       } else if (launchType == 2) {
3160         LaunchEntrezURL ("Structure", uid, "DocSum");
3161       } else if (launchType == 3) {
3162         LaunchStructureASN (uid);
3163       }
3164     } else if (StringICmp (dbName, "Genome") == 0) {
3165       sprintf (id, "gnl|NCBI_GENOMES|%ld", (long) uid);
3166       sip = SeqIdParse (id);
3167       uid = GetGIForSeqId (sip);
3168       SeqIdFree (sip);
3169       if (launchType == 1) {
3170         LaunchSequenceViewer (uid, numAlign, alignuids, "Nucleotide");
3171       } else if (launchType == 2) {
3172         LaunchSequin (uid, numAlign, alignuids, dbName);
3173       } else if (launchType == 3) {
3174         LaunchEntrezURL ("Genome", uid, "DocSum");
3175       } else if (launchType == 4) {
3176         LaunchSequenceASN (uid);
3177       }
3178     } else if (StringICmp (dbName, "Popset") == 0) {
3179       if (launchType == 1) {
3180         LaunchSequenceViewer (uid, numAlign, alignuids, dbName);
3181       } else if (launchType == 2) {
3182         LaunchSequin (uid, numAlign, alignuids, dbName);
3183       } else if (launchType == 3) {
3184         LaunchEntrezURL ("Popset", uid, "DocSum");
3185       } else if (launchType == 4) {
3186         LaunchSequenceASN (uid);
3187       }
3188     } else if (StringICmp (dbName, "OMIM") == 0) {
3189       if (launchType == 1) {
3190         LaunchEntrezURL ("OMIM", uid, "DocSum");
3191       } else if (launchType == 2) {
3192         LaunchMimASN (uid);
3193       }
3194     } else if (StringICmp (dbName, "Taxonomy") == 0) {
3195       if (launchType == 1) {
3196         LaunchEntrezURL ("Taxonomy", uid, "DocSum");
3197       }
3198     } else if (StringICmp (dbName, "Books") == 0) {
3199       if (launchType == 1) {
3200         LaunchEntrezURL ("Books", uid, "DocSum");
3201       }
3202     } else if (StringICmp (dbName, "geo") == 0) {
3203       if (launchType == 1) {
3204         LaunchEntrezURL ("geo", uid, "DocSum");
3205       }
3206     } else if (StringICmp (dbName, "domains") == 0) {
3207       if (launchType == 1) {
3208         LaunchEntrezURL ("domains", uid, "DocSum");
3209       }
3210     } else if (StringICmp (dbName, "unists") == 0) {
3211       if (launchType == 1) {
3212         LaunchEntrezURL ("unists", uid, "DocSum");
3213       }
3214     } else if (StringICmp (dbName, "cdd") == 0) {
3215       if (launchType == 1) {
3216         LaunchEntrezURL ("cdd", uid, "DocSum");
3217       }
3218     } else if (StringICmp (dbName, "snp") == 0) {
3219       if (launchType == 1) {
3220         LaunchEntrezURL ("snp", uid, "DocSum");
3221       }
3222     } else if (StringICmp (dbName, "journals") == 0) {
3223       if (launchType == 1) {
3224         LaunchEntrezURL ("journals", uid, "DocSum");
3225       }
3226     } else if (StringICmp (dbName, "unigene") == 0) {
3227       if (launchType == 1) {
3228         LaunchEntrezURL ("unigene", uid, "DocSum");
3229       }
3230     } else if (StringICmp (dbName, "PMC") == 0) {
3231       if (launchType == 1) {
3232         LaunchEntrezURL ("PMC", uid, "DocSum");
3233       }
3234     } else if (StringICmp (dbName, "ncbiserach") == 0) {
3235       if (launchType == 1) {
3236         LaunchEntrezURL ("ncbisearch", uid, "DocSum");
3237       }
3238     } else if (StringICmp (dbName, "mesh") == 0) {
3239       if (launchType == 1) {
3240         LaunchEntrezURL ("mesh", uid, "DocSum");
3241       }
3242     } else if (StringICmp (dbName, "gene") == 0) {
3243       if (launchType == 1) {
3244         LaunchEntrezURL ("gene", uid, "DocSum");
3245       }
3246     } else {
3247       /* default so new databases work without code changes */
3248       LaunchEntrezURL (dbName, uid, "DocSum");
3249     }
3250   }
3251 }
3252 
3253 /*==================================================================*/
3254 /*                                                                  */
3255 /*  ReleaseDocSum () -                                              */
3256 /*                                                                  */
3257 /*==================================================================*/
3258 
ReleaseDocSum(DoC d,PoinT pt)3259 static void ReleaseDocSum (DoC d, PoinT pt)
3260 
3261 {
3262   Int2         checked;
3263   Int2         col;
3264   Int2         db;
3265   Int2         item;
3266   Int2         num;
3267   RecT         r;
3268   Int2         row;
3269   SummFormPtr  sfp;
3270   Int4         uid;
3271   Int4Ptr      uids;
3272   Int2         val;
3273 
3274   sfp = (SummFormPtr) GetObjectExtra (d);
3275   if (sfp == NULL) return;
3276   MapDocPoint (d, pt, &item, &row, &col, &r);
3277   if (item < 1 || item > sfp->numUids || row == 0 || col == 0) return;
3278   if (sfp->dsClickItem != item) return;
3279   if (row == 1 && col == 1 && sfp->dsClickRow == 1 && sfp->dsClickCol == 1) {
3280     r.right = r.left + sfp->lineHeight;
3281     r.bottom = r.top + sfp->lineHeight;
3282     if (PtInRect (pt, &r)) {
3283       checked = sfp->state [item - 1].checked;
3284       sfp->state [item - 1].checked = (Boolean) (!checked);
3285       ObjectRect (d, &r);
3286       InsetRect (&r, 4, 4);
3287       r.right = r.left + sfp->lineHeight;
3288       InsetRect (&r, -1, -1);
3289       InvalRect (&r);
3290       ResetClip ();
3291       WatchCursor ();
3292       Update ();
3293       sfp->retrieveMode = EVAL_MODE;
3294       RecalculateDocSum (sfp);
3295       ArrowCursor ();
3296       Update ();
3297       return;
3298     }
3299   }
3300 
3301   if (sfp->wasDoubleClick && sfp->uids != NULL && sfp->simple == NULL) {
3302     db = sfp->currDb;
3303     uid = sfp->uids [item - 1];
3304     uids = GetCheckedUids (sfp, &num);
3305     if (sfp->launchPopups != NULL) {
3306       val = GetValue (sfp->launchPopups [db]);
3307       LaunchRecViewer (sfp->form, uid, num, uids, db, val);
3308       MemFree (uids);
3309       return;
3310     }
3311     LaunchRecViewer (sfp->form, uid, num, uids, db, 1);
3312     MemFree (uids);
3313   }
3314 }
3315 
3316 
3317 /*==================================================================*/
3318 /*                                                                  */
3319 /*  RefineProc () -                                                 */
3320 /*                                                                  */
3321 /*==================================================================*/
3322 
3323 static int  refinement = 0;  /* Guarantees that each refinement has a unique name. */
3324 
RefineProc(ButtoN b)3325 static void RefineProc (ButtoN b)
3326 
3327 {
3328   Int2         i;
3329   Int2         num;
3330   SummFormPtr  sfp;
3331   Char         str [64];
3332   Int4Ptr      uids;
3333 
3334   /*--------------------------*/
3335   /* Check initial conditions */
3336   /*--------------------------*/
3337 
3338   sfp = (SummFormPtr) GetObjectExtra (b);
3339   if (sfp == NULL || sfp->refineUidProc == NULL) return;
3340 
3341   /*------------------------------*/
3342   /* Get a count of checked items */
3343   /*------------------------------*/
3344 
3345   num = 0;
3346   for (i = 0; i < sfp->numUids; i++) {
3347     if (sfp->state [i].checked) {
3348       num++;
3349     }
3350   }
3351 
3352   /*------------------------------------------*/
3353   /* If any items are checked, then use them, */
3354   /* otherwise use all the current UIDs.      */
3355   /*------------------------------------------*/
3356 
3357   refinement++;
3358   sprintf (str, "*generation_%d_refinement_%d", (int) sfp->present, (int) refinement);
3359   if (num > 0) {
3360     uids = MemNew ((size_t) (num + 1) * sizeof (DocUid));
3361     if (uids != NULL) {
3362       num = 0;
3363       for (i = 0; i < sfp->numUids; i++) {
3364         if (sfp->state [i].checked) {
3365           uids [num] = sfp->uids [i];
3366           num++;
3367         }
3368       }
3369       sfp->refineUidProc (sfp->form, str, num, uids, sfp->currDb);
3370     }
3371     MemFree (uids);
3372   } else {
3373     sfp->refineUidProc (sfp->form, str, sfp->numUids, sfp->uids, sfp->currDb);
3374   }
3375 }
3376 
3377 /*==================================================================*/
3378 /*                                                                  */
3379 /*  UidInList () -                                                  */
3380 /*                                                                  */
3381 /*==================================================================*/
3382 
UidInList(Int4 uid,Int4Ptr sorted,Int2 num)3383 static Boolean UidInList (Int4 uid, Int4Ptr sorted, Int2 num)
3384 
3385 {
3386   Boolean  found;
3387   Int2     left;
3388   Int2     mid;
3389   Int2     right;
3390 
3391   found = FALSE;
3392   if (sorted != NULL && num > 0) {
3393     mid = 0;
3394     left = 0;
3395     right = num - 1;
3396     while (left <= right) {
3397       mid = (left + right) / 2;
3398       if (uid <= sorted [mid]) {
3399         right = mid - 1;
3400       }
3401       if (uid >= sorted [mid]) {
3402         left = mid + 1;
3403       }
3404     }
3405     if (left > right + 1) {
3406       found = TRUE;
3407     }
3408   }
3409   return found;
3410 }
3411 
3412 /*==================================================================*/
3413 /*                                                                  */
3414 /*  RetrieveNeighbors () -                                          */
3415 /*                                                                  */
3416 /*==================================================================*/
3417 
RetrieveNeighbors(ButtoN b)3418 static void RetrieveNeighbors (ButtoN b)
3419 
3420 {
3421   Entrez2GlobalsPtr  egp;
3422   Int2               i, j;
3423   Int2               num;
3424   Int2               parents;
3425   Boolean            persist;
3426   SummFormPtr        sfp;
3427   Int4Ptr            sorted;
3428   Int4               tmp;
3429   Int4Ptr            uids;
3430   CharPtr            dbName;
3431 
3432   sfp = (SummFormPtr) GetObjectExtra (b);
3433   if (sfp == NULL) return;
3434 
3435   if (sfp->retrieveMode == EVAL_MODE && sfp->usingDelay) {
3436     WatchCursor ();
3437     Update ();
3438     sfp->retrieveMode = FETCH_MODE;
3439     RecalculateDocSum (sfp);
3440     ArrowCursor ();
3441     Update ();
3442     return;
3443   }
3444 
3445   egp = (Entrez2GlobalsPtr) GetAppProperty ("Entrez2Globals");
3446   if (egp == NULL) return;
3447 
3448   persist = FALSE;
3449   if (sfp->currDb == sfp->neighborDb)
3450     persist = GetStatus (egp->parentsPersist);
3451 
3452   parents = 0;
3453   if (persist) {
3454     for (i = 0; i < sfp->numUids; i++) {
3455       if (sfp->state [i].checked) {
3456         parents++;
3457       }
3458     }
3459   }
3460 
3461   uids = NULL;
3462   sorted = NULL;
3463   num = parents + sfp->numNeighbors;
3464 
3465   if (num > 0) {
3466     uids = MemNew ((size_t) (num + 1) * sizeof (DocUid));
3467     sorted = MemNew ((size_t) (parents + 1) * sizeof (DocUid));
3468     if (uids != NULL && sorted != NULL) {
3469       num = 0;
3470       if (persist && sfp->uids != NULL) {
3471         for (i = 0; i < sfp->numUids; i++) {
3472           if (sfp->state [i].checked) {
3473             uids [num] = sfp->uids [i];
3474             sorted [num] = sfp->uids [i];
3475             num++;
3476           }
3477         }
3478         for (i = 1; i < parents; i++) {
3479           for (j = 0; j < i; j++) {
3480             if (sorted [j] > sorted [i]) {
3481               tmp = sorted [i];
3482               sorted [i] = sorted [j];
3483               sorted [j] = tmp;
3484             }
3485           }
3486         }
3487       }
3488       if (sfp->neighbors != NULL) {
3489         for (i = 0; i < sfp->numNeighbors; i++) {
3490           if (!UidInList (sfp->neighbors [i], sorted, parents)) {
3491             uids [num] = sfp->neighbors [i];
3492             num++;
3493           }
3494         }
3495       }
3496     }
3497   }
3498   sfp->neighbors = NULL;
3499   sfp->numNeighbors = 0;
3500   dbName = DBGetNameFromID (sfp->neighborDb);
3501   RetrieveDocs (sfp->form, num, parents, uids, dbName);
3502   MemFree (uids);
3503   MemFree (sorted);
3504 }
3505 
3506 /*==================================================================*/
3507 /*                                                                  */
3508 /*  EntrezDocSumFormActivate_Callback () = Called when the Document */
3509 /*         summary window is made active. Mostly just calls the     */
3510 /*         function provided by the controlling program.            */
3511 /*                                                                  */
3512 /*==================================================================*/
3513 
EntrezDocSumFormActivate_Callback(WindoW w)3514 static void EntrezDocSumFormActivate_Callback (WindoW w)
3515 
3516 {
3517   SummFormPtr  sfp;
3518 
3519   sfp = (SummFormPtr) GetObjectExtra (w);
3520   if (sfp != NULL) {
3521     if (sfp->activate != NULL)
3522       sfp->activate (w);
3523     SetDocSumImportExportItems (sfp);
3524   }
3525 }
3526 
3527 /*==================================================================*/
3528 /*                                                                  */
3529 /*  CopyDocsumToClipboard () -                                      */
3530 /*                                                                  */
3531 /*==================================================================*/
3532 
CopyDocsumToClipboard(BaseFormPtr bfp)3533 static void CopyDocsumToClipboard (BaseFormPtr bfp)
3534 
3535 {
3536   FILE         *fp;
3537   Int2         i;
3538   Boolean      newline;
3539   Int2         num;
3540   Char         path [PATH_MAX];
3541   SummFormPtr  sfp;
3542 
3543   sfp = (SummFormPtr) bfp;
3544   if (sfp == NULL) return;
3545   TmpNam (path);
3546   fp = FileOpen (path, "w");
3547   if (fp != NULL) {
3548     num = 0;
3549     for (i = 0; i < sfp->numUids; i++) {
3550       if (sfp->state [i].checked) {
3551         num++;
3552       }
3553     }
3554     if (num == 0) {
3555       SaveDocument (sfp->docsum, fp);
3556     } else {
3557       newline = FALSE;
3558       for (i = 0; i < sfp->numUids; i++) {
3559         if (sfp->state [i].checked) {
3560           if (newline) {
3561             fputc ('\n', fp);
3562           }
3563           SaveDocumentItem (sfp->docsum, fp, i + 1);
3564           newline = TRUE;
3565         }
3566       }
3567     }
3568     FileClose (fp);
3569     FileToClipboard (path);
3570   }
3571   FileRemove (path);
3572 }
3573 
3574 /*==================================================================*/
3575 /*                                                                  */
3576 /*  PrintDocsumProc () -                                            */
3577 /*                                                                  */
3578 /*==================================================================*/
3579 
PrintDocsumProc(BaseFormPtr bfp)3580 static void PrintDocsumProc (BaseFormPtr bfp)
3581 
3582 {
3583   SummFormPtr  sfp;
3584 
3585   if (bfp == NULL) return;
3586   sfp = (SummFormPtr) bfp;
3587   WatchCursor ();
3588   Update ();
3589   PrintDocument (sfp->docsum);
3590   ArrowCursor ();
3591   Update ();
3592 }
3593 
3594 /*==================================================================*/
3595 /*                                                                  */
3596 /*  SaveDocsumProject () -                                          */
3597 /*                                                                  */
3598 /*==================================================================*/
3599 
SaveDocsumProject(BaseFormPtr bfp,Boolean saveAs)3600 static Boolean SaveDocsumProject (BaseFormPtr bfp, Boolean saveAs)
3601 
3602 {
3603   AsnIoPtr     aop;
3604   Char         path [PATH_MAX];
3605   ProjectPtr   proj;
3606   SummFormPtr  sfp;
3607 
3608 #ifdef WIN_MAC
3609   FILE         *fp;
3610 #endif
3611 
3612   if (bfp != NULL) {
3613     sfp = (SummFormPtr) bfp;
3614     path [0] = '\0';
3615     StringNCpy_0 (path, bfp->filepath, sizeof (path));
3616     if (StringHasNoText (path) || saveAs) {
3617       if (!(GetOutputFileName (path, sizeof (path), "")))
3618         return FALSE;
3619     }
3620 #ifdef WIN_MAC
3621     fp = FileOpen (path, "r");
3622     if (fp != NULL) {
3623       FileClose (fp);
3624     } else {
3625       FileCreate (path, "TEXT", "ttxt");
3626     }
3627 #endif
3628     WatchCursor ();
3629     Update ();
3630     proj = (ProjectPtr) FormToPointer (bfp->form);
3631     if (proj == NULL) {
3632       ArrowCursor ();
3633       Update ();
3634       Message (MSG_ERROR, "Unable to create project data.");
3635       return FALSE;
3636     }
3637     aop = AsnIoOpen (path, "w");
3638     if (aop != NULL) {
3639       ProjectAsnWrite (proj, aop, NULL);
3640       AsnIoFlush (aop);
3641       AsnIoClose (aop);
3642       bfp->filepath = MemFree (bfp->filepath);
3643       bfp->filepath = StringSave (path);
3644       ArrowCursor ();
3645       Update ();
3646       return TRUE;
3647     } else {
3648       ArrowCursor ();
3649       Update ();
3650       Message (MSG_ERROR, "Unable to write file.");
3651       return FALSE;
3652     }
3653   }
3654   return FALSE;
3655 }
3656 
3657 /*==================================================================*/
3658 /*                                                                  */
3659 /*  ImportDocSumForm () -                                           */
3660 /*                                                                  */
3661 /*==================================================================*/
3662 
ImportDocSumForm(ForM f,CharPtr filename)3663 static Boolean ImportDocSumForm (ForM f, CharPtr filename)
3664 
3665 {
3666   Pointer            dataptr;
3667   Uint2              datatype;
3668   Entrez2GlobalsPtr  egp;
3669   FILE               *fp;
3670   ValNodePtr         head = NULL;
3671   Char               path [PATH_MAX];
3672   ValNodePtr         simples;
3673   SummFormPtr        sfp;
3674   ValNodePtr         vnp;
3675 
3676   path [0] = '\0';
3677   StringNCpy_0 (path, filename, sizeof (path));
3678   sfp = (SummFormPtr) GetObjectExtra (f);
3679   if (sfp != NULL) {
3680     if (path [0] != '\0' || GetInputFileName (path, sizeof (path), "", "TEXT")) {
3681       fp = FileOpen (path, "r");
3682       if (fp != NULL) {
3683         while ((dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, NULL, FALSE, FALSE, TRUE, TRUE)) != NULL)
3684           ValNodeAddPointer (&head, datatype, dataptr);
3685         FileClose (fp);
3686         simples = ValNodeExtractList (&head, OBJ_FASTA);
3687         if (simples != NULL) {
3688           egp = (Entrez2GlobalsPtr) GetAppProperty ("Entrez2Globals");
3689           if (egp != NULL && egp->retrieveSimpleProc != NULL)
3690             egp->retrieveSimpleProc (NULL, simples);
3691         }
3692         ValNodeFree (simples);
3693         if (head != NULL) {
3694           for (vnp = head; vnp != NULL; vnp = vnp->next) {
3695             datatype = vnp->choice;
3696             dataptr = vnp->data.ptrvalue;
3697           }
3698         }
3699         ValNodeFree (head);
3700         return TRUE;
3701       }
3702     }
3703   }
3704 
3705   return FALSE;
3706 }
3707 
3708 /*==================================================================*/
3709 /*                                                                  */
3710 /*  ExportDocSumForm () -                                           */
3711 /*                                                                  */
3712 /*==================================================================*/
3713 
ExportDocSumForm(ForM f,CharPtr filename)3714 static Boolean ExportDocSumForm (ForM f, CharPtr filename)
3715 
3716 {
3717   FILE          *fp;
3718   Int2          i;
3719   CharPtr       dbName;
3720   CharPtr PNTR  labels = defaultRadios;
3721   Boolean       lastChoiceIsUidList = FALSE;
3722   MonitorPtr    mon;
3723   Boolean       newline;
3724   Int2          num;
3725   Char          path [PATH_MAX];
3726   SummFormPtr   sfp;
3727   Char          str [32];
3728   Int2          val;
3729 
3730  /*----------------------*/
3731   /* Get SummFormPtr info */
3732  /*----------------------*/
3733 
3734   sfp = (SummFormPtr) GetObjectExtra (f);
3735 
3736   if (sfp == NULL) return FALSE;
3737 
3738  /*--------------------------------*/
3739   /* If no filename was passed, get */
3740   /* one from the user.             */
3741  /*--------------------------------*/
3742 
3743   path [0] = '\0';
3744   StringNCpy_0 (path, filename, sizeof (path));
3745 
3746   if (path [0] == '\0' && !GetOutputFileName (path, sizeof (path), NULL)) return FALSE;
3747 
3748  /*------------------------------------------*/
3749   /* On the Mac force the file to get created */
3750   /* with the desired attributes.             */
3751  /*------------------------------------------*/
3752 
3753 #ifdef WIN_MAC
3754   fp = FileOpen (path, "r");
3755   if (fp != NULL)
3756     FileClose (fp);
3757   else
3758     FileCreate (path, "TEXT", "ttxt");
3759 #endif
3760 
3761  /*---------------------------*/
3762   /* Open the file for writing */
3763  /*---------------------------*/
3764 
3765   fp = FileOpen (path, "w");
3766   if (fp == NULL) {
3767     Message (MSG_ERROR, "Unable to write file.");
3768     return FALSE;
3769   }
3770 
3771  /*---------------------------------------------*/
3772   /* Indicate 'working' state by changing cursor */
3773  /*---------------------------------------------*/
3774 
3775   WatchCursor ();
3776   Update ();
3777 
3778  /*---------------------------------*/
3779   /* Determine whether or not we are */
3780   /* currently in UID display mode.  */
3781  /*---------------------------------*/
3782 
3783   if (sfp->simple != NULL) {
3784   } else if (sfp->currDb >= 0 && sfp->currDb < MAX_DBS) {
3785     dbName = DBGetNameFromID (sfp->currDb);
3786     if (StringICmp (dbName, "PubMed") == 0)
3787       labels = medRadios;
3788     else if (StringICmp (dbName, "Protein") == 0)
3789       labels = prtRadios;
3790     else if (StringICmp (dbName, "Nucleotide") == 0)
3791       labels = nucRadios;
3792     else if (StringICmp (dbName, "nuccore") == 0)
3793       labels = nucRadios;
3794     else if (StringICmp (dbName, "Structure") == 0)
3795       labels = strucRadios;
3796     else if (StringICmp (dbName, "Genome") == 0)
3797       labels = genRadios;
3798     else if (StringICmp (dbName, "PopSet") == 0)
3799       labels = popsetRadios;
3800     else if (StringICmp (dbName, "OMIM") == 0)
3801       labels = omimRadios;
3802     else if (StringICmp (dbName, "Taxonomy") == 0)
3803       labels = taxonomyRadios;
3804     else if (StringICmp (dbName, "Books") == 0)
3805       labels = bookRadios;
3806     else if (StringICmp (dbName, "geo") == 0)
3807       labels = probeRadios;
3808     else if (StringICmp (dbName, "domains") == 0)
3809       labels = domainRadios;
3810     else if (StringICmp (dbName, "unists") == 0)
3811       labels = stsRadios;
3812     else if (StringICmp (dbName, "cdd") == 0)
3813       labels = cddRadios;
3814     else if (StringICmp (dbName, "snp") == 0)
3815       labels = snpRadios;
3816     else if (StringICmp (dbName, "journals") == 0)
3817       labels = journalsRadios;
3818     else if (StringICmp (dbName, "unigene") == 0)
3819       labels = unigeneRadios;
3820     else if (StringICmp (dbName, "PMC") == 0)
3821       labels = pmcRadios;
3822     else if (StringICmp (dbName, "ncbisearch") == 0)
3823       labels = ncbisearchRadios;
3824     else if (StringICmp (dbName, "mesh") == 0)
3825       labels = meshRadios;
3826     else if (StringICmp (dbName, "gene") == 0)
3827       labels = geneRadios;
3828     else
3829       labels = defaultRadios;
3830 
3831     val = GetValue (sfp->formatPopups [sfp->currDb]);
3832     if (val > 0)
3833       if (labels [val] == NULL)
3834         lastChoiceIsUidList = TRUE;
3835   }
3836 
3837  /*-----------------------------*/
3838   /* If we're writing a UID list */
3839   /* then get a header for it.   */
3840  /*-----------------------------*/
3841 
3842   if (lastChoiceIsUidList) {
3843     switch (sfp->currDb) {
3844       case 0:
3845         fprintf (fp, ">PubMed\n");
3846         break;
3847       case 1:
3848         fprintf (fp, ">Protein\n");
3849         break;
3850       case 2:
3851         fprintf (fp, ">Nucleotide\n");
3852         break;
3853       case 3:
3854         fprintf (fp, ">Structure\n");
3855         break;
3856       case 4:
3857         fprintf (fp, ">Genome\n");
3858         break;
3859       case 5:
3860         fprintf (fp, ">Popset\n");
3861         break;
3862       case 6:
3863         fprintf (fp, ">OMIM\n");
3864         break;
3865       case 7:
3866         fprintf (fp, ">Taxonomy\n");
3867         break;
3868       case 8:
3869         fprintf (fp, ">Books\n");
3870         break;
3871       case 9:
3872         fprintf (fp, ">Probes\n");
3873         break;
3874       case 10:
3875         fprintf (fp, ">Domains\n");
3876         break;
3877       case 11:
3878         fprintf (fp, ">UniSTS\n");
3879         break;
3880       case 12:
3881         fprintf (fp, ">CDD\n");
3882         break;
3883       case 13:
3884         fprintf (fp, ">SNP\n");
3885         break;
3886       case 14:
3887         fprintf (fp, ">Journals\n");
3888         break;
3889       case 15:
3890         fprintf (fp, ">UniGene\n");
3891         break;
3892       case 16:
3893         fprintf (fp, ">PMC\n");
3894         break;
3895       case 17:
3896         fprintf (fp, ">NCBISearch\n");
3897         break;
3898       case 18:
3899         fprintf (fp, ">MeSH\n");
3900         break;
3901       case 19:
3902         fprintf (fp, ">Gene\n");
3903         break;
3904       default:
3905         fprintf (fp, ">?\n");
3906         break;
3907     }
3908   }
3909 
3910  /*-----------------------------*/
3911   /* Determine how many (if any) */
3912   /* items have been checked.    */
3913  /*-----------------------------*/
3914 
3915   num = 0;
3916   for (i = 0; i < sfp->numUids; i++) {
3917     if (sfp->state [i].checked) {
3918       num++;
3919     }
3920   }
3921 
3922  /*------------------------------*/
3923   /* Write to the file either the */
3924   /* or the document summaries.   */
3925  /*------------------------------*/
3926 
3927   if (lastChoiceIsUidList) {
3928     if (num == 0) {
3929       for (i = 0; i < sfp->numUids; i++) {
3930         sprintf (str, "%ld\n", (long) (sfp->uids [i]));
3931         FilePuts (str, fp);
3932       }
3933     } else {
3934       for (i = 0; i < sfp->numUids; i++) {
3935         if (sfp->state [i].checked) {
3936           sprintf (str, "%ld\n", (long) (sfp->uids [i]));
3937           FilePuts (str, fp);
3938         }
3939       }
3940     }
3941   } else {
3942     mon = MonitorIntNewEx ("Saving Documents", 0, sfp->numUids, FALSE);
3943     newline = FALSE;
3944     for (i = 0; i < sfp->numUids; i++) {
3945       if (num == 0 || sfp->state [i].checked) {
3946         if (newline)
3947           fputc ('\n', fp);
3948         SaveDocumentItem (sfp->docsum, fp, i + 1);
3949         MonitorIntValue (mon, i);
3950         newline = TRUE;
3951       }
3952     }
3953     MonitorFree (mon);
3954   }
3955 
3956  /*----------------------------------*/
3957   /* Clean up and return successfully */
3958  /*----------------------------------*/
3959 
3960   FileClose (fp);
3961   sfp->filepath = MemFree (sfp->filepath);
3962   sfp->filepath = StringSave (path);
3963   ArrowCursor ();
3964   Update ();
3965   return TRUE;
3966 
3967 }
3968 
3969 /*================================================================*/
3970 /*                                                                */
3971 /*  EntrezDocSumFormMessage_Callback () = This function is set up */
3972 /*       to receive the messages generated by menu items that are */
3973 /*       created with FormCommandItem().                          */
3974 /*                                                                */
3975 /*================================================================*/
3976 
EntrezDocSumFormMessage_Callback(ForM f,Int2 mssg)3977 static void EntrezDocSumFormMessage_Callback (ForM f, Int2 mssg)
3978 
3979 {
3980   BaseFormPtr        bfp;
3981   Entrez2GlobalsPtr  egp;
3982   SummFormPtr        sfp;
3983 
3984   bfp = (BaseFormPtr) GetObjectExtra (f);
3985   if (bfp != NULL) {
3986     switch (mssg) {
3987       case VIB_MSG_REDRAW:
3988         egp = (Entrez2GlobalsPtr) GetAppProperty ("Entrez2Globals");
3989         if (egp != NULL) {
3990           sfp = (SummFormPtr) bfp;
3991           sfp->docsumFont = egp->docsumFont;
3992           RepopulateDocSum (sfp, TRUE);
3993         }
3994         break;
3995       case VIB_MSG_COPY:
3996         CopyDocsumToClipboard (bfp);
3997         break;
3998       case VIB_MSG_IMPORT:
3999         ImportDocSumForm (f, NULL);
4000         break;
4001       case VIB_MSG_EXPORT:
4002         ExportDocSumForm (f, NULL);
4003         break;
4004       case VIB_MSG_PRINT:
4005         PrintDocsumProc (bfp);
4006         break;
4007       case VIB_MSG_SAVE_AS:
4008         SaveDocsumProject (bfp, TRUE);
4009         break;
4010       default:
4011         if (bfp->appmessage != NULL) {
4012           bfp->appmessage (f, mssg);
4013         }
4014         break;
4015     }
4016   }
4017 }
4018 
4019 /*==================================================================*/
4020 /*                                                                  */
4021 /*  RefreshAndRecalculateDocSum () -                                */
4022 /*                                                                  */
4023 /*==================================================================*/
4024 
RefreshAndRecalculateDocSum(SummFormPtr sfp)4025 static void RefreshAndRecalculateDocSum (SummFormPtr sfp)
4026 
4027 {
4028   RecT  r;
4029 
4030   if (sfp == NULL) return;
4031   Select (sfp->docsum);
4032   ObjectRect (sfp->docsum, &r);
4033   InsetRect (&r, 4, 4);
4034   r.right = r.left + sfp->lineHeight;
4035   InsetRect (&r, -1, -1);
4036   InvalRect (&r);
4037   ResetClip ();
4038   WatchCursor ();
4039   Update ();
4040   sfp->retrieveMode = EVAL_MODE;
4041   RecalculateDocSum (sfp);
4042   ArrowCursor ();
4043   Update ();
4044 }
4045 
4046 /*==================================================================*/
4047 /*                                                                  */
4048 /*  SelectAllProc () -                                              */
4049 /*                                                                  */
4050 /*==================================================================*/
4051 
SelectAllProc(ButtoN b)4052 static void SelectAllProc (ButtoN b)
4053 
4054 {
4055   Int2         i;
4056   SummFormPtr  sfp;
4057 
4058   sfp = (SummFormPtr) GetObjectExtra (b);
4059   if (sfp == NULL) return;
4060   for (i = 0; i < sfp->numUids; i++) {
4061     sfp->state [i].checked = TRUE;
4062   }
4063   RefreshAndRecalculateDocSum (sfp);
4064 }
4065 
4066 /*==================================================================*/
4067 /*                                                                  */
4068 /*  SelectParentsProc () -                                          */
4069 /*                                                                  */
4070 /*==================================================================*/
4071 
SelectParentsProc(ButtoN b)4072 static void SelectParentsProc (ButtoN b)
4073 
4074 {
4075   Int2         i;
4076   SummFormPtr  sfp;
4077 
4078   sfp = (SummFormPtr) GetObjectExtra (b);
4079   if (sfp == NULL) return;
4080   for (i = 0; i < sfp->numUids; i++) {
4081     sfp->state [i].checked = (Boolean) (i < sfp->numParents);
4082   }
4083   RefreshAndRecalculateDocSum (sfp);
4084 }
4085 
4086 /*==================================================================*/
4087 /*                                                                  */
4088 /*  ClearAllProcs () -                                              */
4089 /*                                                                  */
4090 /*==================================================================*/
4091 
ClearAllProc(ButtoN b)4092 static void ClearAllProc (ButtoN b)
4093 
4094 {
4095   Int2         i;
4096   SummFormPtr  sfp;
4097 
4098   sfp = (SummFormPtr) GetObjectExtra (b);
4099   if (sfp == NULL) return;
4100   for (i = 0; i < sfp->numUids; i++) {
4101     sfp->state [i].checked = FALSE;
4102   }
4103   RefreshAndRecalculateDocSum (sfp);
4104 }
4105 
4106 /*==================================================================*/
4107 /*                                                                  */
4108 /*  SetPrevAndNextButtons () -                                      */
4109 /*                                                                  */
4110 /*==================================================================*/
4111 
SetPrevAndNextButtons(SummFormPtr sfp)4112 static void SetPrevAndNextButtons (SummFormPtr sfp)
4113 
4114 {
4115   if (sfp->present > 1)
4116     SafeEnable (sfp->prevBtn);
4117   else
4118     SafeDisable (sfp->prevBtn);
4119 
4120   if (sfp->present < sfp->generations)
4121     SafeEnable (sfp->nextBtn);
4122   else
4123     SafeDisable (sfp->nextBtn);
4124 }
4125 
4126 /*==================================================================*/
4127 /*                                                                  */
4128 /*  RetrieveGeneration () -                                         */
4129 /*                                                                  */
4130 /*==================================================================*/
4131 
RetrieveGeneration(SummFormPtr sfp,Int2 num,Int2 parents,Int4Ptr uids,Int2 db)4132 static void RetrieveGeneration (SummFormPtr sfp, Int2 num, Int2 parents, Int4Ptr uids, Int2 db)
4133 
4134 {
4135   Entrez2InfoPtr  e2ip;
4136   Int2            i;
4137   Char            title [32];
4138 
4139   if (sfp == NULL || uids == NULL) return;
4140 
4141   /*----------------------------------*/
4142   /* Get information on the databases */
4143   /*----------------------------------*/
4144 
4145   e2ip = Query_GetInfo ();
4146 
4147   /*------------------------------*/
4148   /* Initialize the DocSum window */
4149   /*------------------------------*/
4150 
4151   Reset (sfp->docsum);
4152   SetDocShade (sfp->docsum, NULL, NULL, NULL, NULL);
4153   SetDocCache (sfp->docsum, NULL, NULL, NULL);
4154   sfp->uids = MemFree (sfp->uids);
4155   sfp->formatted = MemFree (sfp->formatted);
4156   if (sfp->simple != NULL) {
4157     for (i = 0; i < sfp->numUids; i++) {
4158       SimpleSeqFree (sfp->simple [i]);
4159     }
4160     sfp->simple = MemFree (sfp->simple);
4161   }
4162   sfp->state = MemFree (sfp->state);
4163   sfp->numUids = 0;
4164   sfp->numParents = 0;
4165   sfp->neighbors = MemFree (sfp->neighbors);
4166   sfp->numNeighbors = 0;
4167   SafeSetTitle (sfp->retrieve, "Neighbor 0");
4168   SafeDisable (sfp->retrieve);
4169   sprintf (title, "Refine %d", (int) num);
4170   SafeSetTitle (sfp->refine, title);
4171   if (num > 0)
4172     SafeEnable (sfp->refine);
4173   else
4174     SafeDisable (sfp->refine);
4175   SetEnumPopup (sfp->target, sfp->dbalist, (UIEnum) db);
4176   SafeShow (sfp->target);
4177   SetPrevAndNextButtons (sfp);
4178   Update ();
4179 
4180   /*-----------------------------------*/
4181   /* Select the proper DB radio button */
4182   /*-----------------------------------*/
4183 
4184   Hide (sfp->formatPopups [MAX_DBS]);
4185   Hide (sfp->launchPopups [MAX_DBS]);
4186   for (i = 0; i < MAX_DBS; i++) {
4187     if (i != db && sfp->formatPopups [i] != NULL)
4188       SafeHide (sfp->formatPopups [i]);
4189     if (i != db && sfp->launchPopups [i] != NULL)
4190       SafeHide (sfp->launchPopups [i]);
4191   }
4192 
4193   if (db < MAX_DBS) {
4194     Show (sfp->formatPopups [db]);
4195     Show (sfp->launchPopups [db]);
4196   }
4197 
4198   /*------------------------------------*/
4199   /* Load the documents into the window */
4200   /*------------------------------------*/
4201 
4202   if (num > 0) {
4203     sfp->uids = MemDup ((Pointer) uids, (size_t) ((num + 1) * sizeof (DocUid)));
4204     if (sfp->uids == NULL) return;
4205     sfp->state = MemNew (sizeof (DocSumStateData) * (size_t) (num + 1));
4206     if (sfp->state == NULL) return;
4207     sfp->formatted = MemNew (sizeof (Boolean) * (size_t) (num + 1));
4208     if (sfp->formatted == NULL) return;
4209     sfp->numUids = num;
4210     sfp->numParents = parents;
4211     sfp->currDb = db;
4212     Show (sfp->form);
4213     Select (sfp->form);
4214     RepopulateDocSum (sfp, FALSE);
4215     SetDocSumImportExportItems (sfp);
4216     SendMessageToForm (sfp->form, VIB_MSG_CHANGE);
4217 #ifdef WIN_MAC
4218     if (sfp->activate != NULL)
4219       sfp->activate ((WindoW) sfp->form);
4220 #endif
4221   } else {
4222     Show (sfp->form);
4223     Select (sfp->form);
4224 #ifdef WIN_MAC
4225     if (sfp->activate != NULL)
4226       sfp->activate ((WindoW) sfp->form);
4227 #endif
4228   }
4229   Update ();
4230 }
4231 
4232 /*==================================================================*/
4233 /*                                                                  */
4234 /*  LoadPresentGeneration ()                                        */
4235 /*                                                                  */
4236 /*==================================================================*/
4237 
LoadPresentGeneration(SummFormPtr sfp)4238 static void LoadPresentGeneration (SummFormPtr sfp)
4239 
4240 {
4241   Int2     db;
4242   FILE     *fp;
4243   Int2     num;
4244   Int2     parents;
4245   Int4Ptr  uids;
4246 
4247   if (sfp == NULL) return;
4248 
4249   WatchCursor ();
4250   if (sfp->historyFile != NULL && sfp->historyOffsets != NULL) {
4251     fp = FileOpen (sfp->historyFile, "rb");
4252     if (fp != NULL) {
4253       fseek (fp, sfp->historyOffsets [(sfp->present) % 100], SEEK_SET);
4254       FileRead (&db, sizeof (db), 1, fp);
4255       FileRead (&num, sizeof (num), 1, fp);
4256       FileRead (&parents, sizeof (parents), 1, fp);
4257       uids = (Int4Ptr) MemNew ((size_t) num * sizeof (Int4) + 4);
4258       if (uids != NULL)
4259         FileRead (uids, sizeof (Int4), (size_t) num, fp);
4260       FileClose (fp);
4261       if (uids != NULL) {
4262         RetrieveGeneration (sfp, num, parents, uids, db);
4263         MemFree (uids);
4264       }
4265     }
4266   }
4267   ArrowCursor ();
4268 }
4269 
4270 /*==================================================================*/
4271 /*                                                                  */
4272 /*  RetrieveDocs ()                                                 */
4273 /*                                                                  */
4274 /*==================================================================*/
4275 
RetrieveDocs(ForM f,Int2 num,Int2 parents,Int4Ptr uids,CharPtr dbName)4276 NLM_EXTERN void RetrieveDocs (ForM f, Int2 num, Int2 parents, Int4Ptr uids, CharPtr dbName)
4277 
4278 {
4279   Int2         db;
4280   FILE         *fp;
4281   Char         path [PATH_MAX];
4282   SummFormPtr  sfp;
4283   Int2         val;
4284 
4285   /*--------------------------*/
4286   /* Check initial conditions */
4287   /*--------------------------*/
4288 
4289   if ((sfp = (SummFormPtr) GetObjectExtra (f)) == NULL) return;
4290 
4291   if (uids == NULL) return;
4292 
4293   db = DBGetIDFromName (dbName);
4294 
4295   /*--------------------------*/
4296   /* Increment the generation */
4297   /*--------------------------*/
4298 
4299   (sfp->generations)++;
4300   sfp->present = sfp->generations;
4301 
4302   /*---------------------------------*/
4303   /* Open the history file, creating */
4304   /* if necessary.                   */
4305   /*---------------------------------*/
4306 
4307   if (sfp->historyFile == NULL) {
4308     TmpNam (path);
4309     sfp->historyFile = StringSave (path);
4310 #ifdef WIN_MAC
4311     if (sfp->historyFile != NULL)
4312       FileCreate (sfp->historyFile, "????", "ENTZ");
4313 #endif
4314   }
4315 
4316   /*------------------------------*/
4317   /* Write the current generation */
4318   /* to the history file.         */
4319   /*------------------------------*/
4320 
4321   if (sfp->historyOffsets == NULL)
4322     sfp->historyOffsets = MemNew (100 * sizeof (Int4));
4323 
4324   if (sfp->historyFile != NULL && sfp->historyOffsets != NULL) {
4325     fp = FileOpen (sfp->historyFile, "ab");
4326     if (fp != NULL) {
4327       fseek (fp, 0, SEEK_END);
4328       sfp->historyOffsets [(sfp->present) % 100] = ftell (fp);
4329       val = db;
4330       FileWrite (&val, sizeof (val), 1, fp);
4331       val = num;
4332       FileWrite (&val, sizeof (val), 1, fp);
4333       val = parents;
4334       FileWrite (&val, sizeof (val), 1, fp);
4335       FileWrite (uids, sizeof (Int4), (size_t) num, fp);
4336       FileClose (fp);
4337     } else
4338       sfp->historyOffsets [sfp->present % 100] = 0;
4339   }
4340 
4341   /*--------------------------------*/
4342   /* Get the new document summaries */
4343   /*--------------------------------*/
4344 
4345   RetrieveGeneration (sfp, num, parents, uids, db);
4346 }
4347 
4348 /*==================================================================*/
4349 /*                                                                  */
4350 /*  PrevButton_Callback () -                                        */
4351 /*                                                                  */
4352 /*==================================================================*/
4353 
PrevButton_Callback(ButtoN b)4354 static void PrevButton_Callback (ButtoN b)
4355 
4356 {
4357   SummFormPtr  sfp;
4358 
4359   sfp = (SummFormPtr) GetObjectExtra (b);
4360   if (sfp == NULL) return;
4361 
4362   (sfp->present)--;
4363   if (sfp->present < 1)
4364     sfp->present = 1;
4365 
4366   SetPrevAndNextButtons (sfp);
4367   LoadPresentGeneration (sfp);
4368   SetDocSumImportExportItems (sfp);
4369 }
4370 
4371 /*==================================================================*/
4372 /*                                                                  */
4373 /*  NextButton_Callback () -                                        */
4374 /*                                                                  */
4375 /*==================================================================*/
4376 
NextButton_Callback(ButtoN b)4377 static void NextButton_Callback (ButtoN b)
4378 
4379 {
4380   SummFormPtr  sfp;
4381 
4382   sfp = (SummFormPtr) GetObjectExtra (b);
4383   if (sfp == NULL) return;
4384 
4385   (sfp->present)++;
4386   if (sfp->present > sfp->generations)
4387     sfp->present = sfp->generations;
4388 
4389   SetPrevAndNextButtons (sfp);
4390   LoadPresentGeneration (sfp);
4391   SetDocSumImportExportItems (sfp);
4392 }
4393 
4394 /*==================================================================*/
4395 /*                                                                  */
4396 /*  NeighborDelayProc () -                                          */
4397 /*                                                                  */
4398 /*==================================================================*/
4399 
NeighborDelayProc(ChoicE c)4400 static void NeighborDelayProc (ChoicE c)
4401 
4402 {
4403   SummFormPtr  sfp;
4404 
4405   sfp = (SummFormPtr) GetObjectExtra (c);
4406 #ifdef WIN_MAC
4407   if (sfp == NULL) {
4408     sfp = (SummFormPtr) currentFormDataPtr;
4409   }
4410 #endif
4411   if (sfp == NULL) return;
4412   if (GetValue (c) == 1) {
4413     sfp->usingDelay = FALSE;
4414   } else {
4415     sfp->usingDelay = TRUE;
4416   }
4417 }
4418 
4419 /*==================================================================*/
4420 /*                                                                  */
4421 /*  CreateNeighborDelayChoice () -                                  */
4422 /*                                                                  */
4423 /*==================================================================*/
4424 
CreateNeighborDelayChoice(MenU m,BaseFormPtr bfp)4425 static ChoicE CreateNeighborDelayChoice (MenU m, BaseFormPtr bfp)
4426 
4427 {
4428   ChoicE       c;
4429   SummFormPtr  sfp;
4430 
4431   sfp = (SummFormPtr) bfp;
4432 
4433   c = ChoiceGroup (m, NeighborDelayProc);
4434   SetObjectExtra (c, bfp, NULL);
4435   ChoiceItem (c, "Immediate");
4436   ChoiceItem (c, "Delayed");
4437   if (sfp->usingDelay == TRUE)
4438     SetValue (c, 2);
4439   else
4440     SetValue (c, 1);
4441 
4442   return c;
4443 }
4444 
4445 /*==================================================================*/
4446 /*                                                                  */
4447 /*  LoadDocsumOptionsMenu () -                                      */
4448 /*                                                                  */
4449 /*==================================================================*/
4450 
LoadDocsumOptionsMenu(MenU m)4451 static void LoadDocsumOptionsMenu (MenU m)
4452 
4453 {
4454   Entrez2GlobalsPtr  egp;
4455   MenU               sub;
4456 
4457   egp = (Entrez2GlobalsPtr) GetAppProperty ("Entrez2Globals");
4458   if (egp == NULL) return;
4459   egp->parentsPersist = StatusItem (m, "Parents Persist", NULL);
4460   SetStatus (egp->parentsPersist, egp->persistDefault);
4461   egp->alignWithChecked = StatusItem (m, "Align Checked Items", NULL);
4462   SetStatus (egp->alignWithChecked, egp->alignDefault);
4463   SeparatorItem (m);
4464   sub = SubMenu (m, "Sequence Complexity");
4465   egp->seqComplex = ChoiceGroup (sub, NULL);
4466   ChoiceItem (egp->seqComplex, "Everything");
4467   ChoiceItem (egp->seqComplex, "NucProt");
4468   ChoiceItem (egp->seqComplex, "SegSet");
4469   ChoiceItem (egp->seqComplex, "BioSeq");
4470   SetValue (egp->seqComplex, 1);
4471   /*
4472   SeparatorItem (m);
4473   sub = SubMenu (m, "Structure Complexity");
4474   egp->strucComplex = ChoiceGroup (sub, NULL);
4475   ChoiceItem (egp->strucComplex, "NCBI one XYZ per atom model");
4476   ChoiceItem (egp->strucComplex, "NCBI backbone model");
4477   ChoiceItem (egp->strucComplex, "Original PDB models 1-n");
4478   ChoiceItem (egp->strucComplex, "NCBI vector model");
4479   ChoiceItem (egp->strucComplex, "Everything");
4480   SetValue (egp->strucComplex, 1);
4481   sub = SubMenu (m, "Number of Models");
4482   egp->strucModels = ChoiceGroup (sub, NULL);
4483   ChoiceItem (egp->strucModels, "1");
4484   ChoiceItem (egp->strucModels, "2");
4485   ChoiceItem (egp->strucModels, "5");
4486   ChoiceItem (egp->strucModels, "10");
4487   ChoiceItem (egp->strucModels, "15");
4488   ChoiceItem (egp->strucModels, "20");
4489   ChoiceItem (egp->strucModels, "maximum");
4490   SetValue (egp->strucModels, 7);
4491   */
4492 }
4493 
4494 /*==================================================================*/
4495 /*                                                                  */
4496 /*  DocSumFontChangeProc () -                                       */
4497 /*                                                                  */
4498 /*==================================================================*/
4499 
DocSumFontChangeProc(IteM i)4500 static void DocSumFontChangeProc (IteM i)
4501 
4502 {
4503   BaseFormPtr        bfp;
4504   Entrez2GlobalsPtr  egp;
4505   Uint2              flags;
4506   FonT               fnt;
4507   FontSpec           fs;
4508   Char               str [FONT_NAME_SIZE + 10];
4509 
4510   egp = (Entrez2GlobalsPtr) GetAppProperty ("Entrez2Globals");
4511 
4512   bfp = GetObjectExtra (i);
4513 #ifdef WIN_MAC
4514   if (bfp == NULL) {
4515     bfp = currentFormDataPtr;
4516   }
4517 #endif
4518   if (bfp != NULL) {
4519     MemSet ((Pointer) (&fs), 0, sizeof (FontSpec));
4520     fnt = programFont;
4521     if (egp != NULL && egp->docsumFont != NULL)
4522       fnt = egp->docsumFont;
4523 
4524     flags = 0;
4525     fs.name [0] = '\0';
4526     fs.size = 0;
4527     fs.style = 0;
4528     fs.charset = 0;
4529     fs.pitch = 0;
4530     fs.family = 0;
4531     if (GetFontSpec (fnt, &fs)) {
4532       flags = CFF_READ_FSP;
4533     }
4534     if (ChooseFont (&fs, flags, NULL)) {
4535       sprintf (str, "%s,%d", fs.name, (int) fs.size);
4536       if ((fs.style & STYLE_BOLD) != 0 || (fs.style & STYLE_ITALIC) != 0 || (fs.style & STYLE_UNDERLINE) != 0) {
4537         StringCat (str, ",");
4538         if ((fs.style & STYLE_BOLD) != 0) {
4539           StringCat (str, "b");
4540         }
4541         if ((fs.style & STYLE_ITALIC) != 0) {
4542           StringCat (str, "i");
4543         }
4544         if ((fs.style & STYLE_UNDERLINE) != 0) {
4545           StringCat (str, "u");
4546         }
4547       }
4548       if (egp != NULL)
4549         egp->docsumFont = CreateFont (&fs);
4550       SendMessageToForm (bfp->form, VIB_MSG_REDRAW);
4551     }
4552   }
4553 }
4554 
4555 /*==================================================================*/
4556 /*                                                                  */
4557 /*  DisplayFontChangeProc () -                                      */
4558 /*                                                                  */
4559 /*==================================================================*/
4560 
DisplayFontChangeProc(IteM i)4561 static void DisplayFontChangeProc (IteM i)
4562 
4563 {
4564   BaseFormPtr          bfp;
4565   Uint2                flags;
4566   FonT                 fnt;
4567   FontSpec             fs;
4568   MedlineViewProcsPtr  mvpp;
4569   Char                 str [FONT_NAME_SIZE + 10];
4570   SeqViewProcsPtr      svpp;
4571 
4572   svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
4573   mvpp = (MedlineViewProcsPtr) GetAppProperty ("MedlineDisplayForm");
4574 
4575   bfp = GetObjectExtra (i);
4576 #ifdef WIN_MAC
4577   if (bfp == NULL) {
4578     bfp = currentFormDataPtr;
4579   }
4580 #endif
4581   if (bfp != NULL) {
4582     MemSet ((Pointer) (&fs), 0, sizeof (FontSpec));
4583     fnt = programFont;
4584     if (svpp != NULL && svpp->displayFont != NULL) {
4585       fnt = svpp->displayFont;
4586     } else if (mvpp != NULL && mvpp->displayFont != NULL) {
4587       fnt = mvpp->displayFont;
4588     }
4589     flags = 0;
4590     fs.name [0] = '\0';
4591     fs.size = 0;
4592     fs.style = 0;
4593     fs.charset = 0;
4594     fs.pitch = 0;
4595     fs.family = 0;
4596     if (GetFontSpec (fnt, &fs)) {
4597       flags = CFF_READ_FSP | CFF_MONOSPACE;
4598     }
4599     if (ChooseFont (&fs, flags, NULL)) {
4600       sprintf (str, "%s,%d", fs.name, (int) fs.size);
4601       if ((fs.style & STYLE_BOLD) != 0 || (fs.style & STYLE_ITALIC) != 0 || (fs.style & STYLE_UNDERLINE) != 0) {
4602         StringCat (str, ",");
4603         if ((fs.style & STYLE_BOLD) != 0) {
4604           StringCat (str, "b");
4605         }
4606         if ((fs.style & STYLE_ITALIC) != 0) {
4607           StringCat (str, "i");
4608         }
4609         if ((fs.style & STYLE_UNDERLINE) != 0) {
4610           StringCat (str, "u");
4611         }
4612       }
4613 
4614       if (svpp != NULL) {
4615         svpp->displayFont = CreateFont (&fs);
4616       }
4617       if (mvpp != NULL) {
4618         mvpp->displayFont = CreateFont (&fs);
4619       }
4620       SendMessageToForm (bfp->form, VIB_MSG_REDRAW);
4621     }
4622   }
4623 }
4624 
4625 /*==================================================================*/
4626 /*                                                                  */
4627 /*  DuplicateViewProc () -                                          */
4628 /*                                                                  */
4629 /*==================================================================*/
4630 
DuplicateViewProc(IteM i)4631 static void DuplicateViewProc (IteM i)
4632 
4633 {
4634   BaseFormPtr  bfp;
4635   Int2         handled;
4636   Uint4        itemID;
4637 
4638   bfp = GetObjectExtra (i);
4639 #ifdef WIN_MAC
4640   if (bfp == NULL) {
4641     bfp = currentFormDataPtr;
4642   }
4643 #endif
4644   if (bfp == NULL) return;
4645   if (bfp->input_itemtype == OBJ_BIOSEQ) {
4646     WatchCursor ();
4647     itemID = bfp->input_itemID;
4648     if (itemID == 0) {
4649       itemID = 1;
4650     }
4651     handled = GatherProcLaunch (OMPROC_VIEW, FALSE, bfp->input_entityID, itemID, OBJ_BIOSEQ, 0, 0, OBJ_BIOSEQ, 0);
4652     ArrowCursor ();
4653     if (handled != OM_MSG_RET_DONE || handled == OM_MSG_RET_NOPROC) {
4654       Message (MSG_ERROR, "Unable to launch additional viewer.");
4655     }
4656   } else if (bfp->input_itemtype == OBJ_MEDLINE_ENTRY) {
4657     WatchCursor ();
4658     itemID = bfp->input_itemID;
4659     if (itemID == 0) {
4660       itemID = 1;
4661     }
4662     handled = GatherProcLaunch (OMPROC_VIEW, FALSE, bfp->input_entityID, itemID, OBJ_MEDLINE_ENTRY, 0, 0, OBJ_MEDLINE_ENTRY, 0);
4663     ArrowCursor ();
4664     if (handled != OM_MSG_RET_DONE || handled == OM_MSG_RET_NOPROC) {
4665       Message (MSG_ERROR, "Unable to launch additional viewer.");
4666     }
4667   }
4668 }
4669 
4670 /*==================================================================*/
4671 /*                                                                  */
4672 /*  CloseProc () -                                                  */
4673 /*                                                                  */
4674 /*==================================================================*/
4675 
CloseProc(BaseFormPtr bfp)4676 static void CloseProc (BaseFormPtr bfp)
4677 
4678 {
4679   Int2                j;
4680   Int2                num;
4681   Boolean             numview;
4682   ObjMgrPtr           omp;
4683   ObjMgrDataPtr PNTR  omdpp;
4684   OMUserDataPtr       omudp;
4685   ObjMgrDataPtr       tmp;
4686 
4687   if (bfp != NULL) {
4688     omp = ObjMgrGet ();
4689     num = omp->currobj;
4690     for (j = 0, omdpp = omp->datalist; j < num && omdpp != NULL; j++, omdpp++) {
4691       tmp = *omdpp;
4692       if (tmp->parentptr == NULL && tmp->dirty && tmp->EntityID == bfp->input_entityID) {
4693         numview = 0;
4694         for (omudp = tmp->userdata; omudp != NULL; omudp = omudp->next) {
4695           if (omudp->proctype == OMPROC_VIEW)
4696             numview++;
4697         }
4698         if (numview < 2)
4699           if (Message (MSG_OKC, "Closing the window will lose unsaved data.")
4700               != ANS_OK)
4701             return;
4702       }
4703     }
4704     numview = 0;
4705     for (j = 0, omdpp = omp->datalist; j < num && omdpp != NULL; j++, omdpp++) {
4706       tmp = *omdpp;
4707       if (tmp->parentptr == NULL)
4708         for (omudp = tmp->userdata; omudp != NULL; omudp = omudp->next)
4709           if (omudp->proctype == OMPROC_VIEW)
4710             numview++;
4711     }
4712     Remove (bfp->form);
4713     if (numview <= 1) {
4714       /*
4715          WatchCursor ();
4716          Update ();
4717          Message (MSG_OK, "No more viewers present.");
4718          ArrowCursor ();
4719          Update ();
4720        */
4721     }
4722   }
4723 }
4724 
4725 /*==================================================================*/
4726 /*                                                                  */
4727 /*  MedlineViewFormMessage_Callback () -                            */
4728 /*                                                                  */
4729 /*==================================================================*/
4730 
MedlineViewFormMessage_Callback(ForM f,Int2 mssg)4731 static void MedlineViewFormMessage_Callback (ForM f, Int2 mssg)
4732 
4733 {
4734   BaseFormPtr  bfp;
4735 
4736   bfp = (BaseFormPtr) GetObjectExtra (f);
4737   if (bfp != NULL) {
4738     switch (mssg) {
4739       case VIB_MSG_CLOSE:
4740         Remove (f);
4741         break;
4742       default:
4743         break;
4744     }
4745   }
4746 }
4747 
4748 /*==================================================================*/
4749 /*                                                                  */
4750 /*  BioseqViewFormMessage_Callback () -                             */
4751 /*                                                                  */
4752 /*==================================================================*/
4753 
BioseqViewFormMessage_Callback(ForM f,Int2 mssg)4754 static void BioseqViewFormMessage_Callback (ForM f, Int2 mssg)
4755 
4756 {
4757   BaseFormPtr  bfp;
4758 
4759   bfp = (BaseFormPtr) GetObjectExtra (f);
4760   if (bfp != NULL) {
4761     switch (mssg) {
4762       case VIB_MSG_CLOSE:
4763         CloseProc (bfp);
4764         break;
4765       default:
4766         break;
4767     }
4768   }
4769 }
4770 
4771 /*==================================================================*/
4772 /*                                                                  */
4773 /*  MedlineViewFormMenus_Callback () -                              */
4774 /*                                                                  */
4775 /*==================================================================*/
4776 
MedlineViewFormMenus_Callback(WindoW w)4777 static void MedlineViewFormMenus_Callback (WindoW w)
4778 
4779 {
4780   BaseFormPtr  bfp;
4781   IteM         i = NULL;
4782   MenU         m;
4783 
4784   bfp = (BaseFormPtr) GetObjectExtra (w);
4785   if (bfp != NULL) {
4786     m = PulldownMenu (w, "File");
4787     FormCommandItem (m, "Close", bfp, VIB_MSG_CLOSE);
4788     SeparatorItem (m);
4789     i = CommandItem (m, "Duplicate View", DuplicateViewProc);
4790     SetObjectExtra (i, bfp, NULL);
4791     SeparatorItem (m);
4792     FormCommandItem (m, "Export...", bfp, VIB_MSG_EXPORT);
4793     SeparatorItem (m);
4794     FormCommandItem (m, "Print...", bfp, VIB_MSG_PRINT);
4795 
4796     m = PulldownMenu (w, "Edit");
4797     FormCommandItem (m, COPY_MENU_ITEM, bfp, VIB_MSG_COPY);
4798   }
4799 }
4800 
4801 /*==================================================================*/
4802 /*                                                                  */
4803 /*  BioseqViewFormMenus_Callback () -                               */
4804 /*                                                                  */
4805 /*==================================================================*/
4806 
BioseqViewFormMenus_Callback(WindoW w)4807 static void BioseqViewFormMenus_Callback (WindoW w)
4808 
4809 {
4810   BaseFormPtr  bfp;
4811   IteM         i = NULL;
4812   MenU         m;
4813   MenU         sub;
4814 
4815   bfp = (BaseFormPtr) GetObjectExtra (w);
4816   if (bfp != NULL) {
4817     m = PulldownMenu (w, "File");
4818     FormCommandItem (m, "Close", bfp, VIB_MSG_CLOSE);
4819     SeparatorItem (m);
4820     i = CommandItem (m, "Duplicate View", DuplicateViewProc);
4821     SetObjectExtra (i, bfp, NULL);
4822     SeparatorItem (m);
4823     FormCommandItem (m, "Export...", bfp, VIB_MSG_EXPORT);
4824     SeparatorItem (m);
4825     FormCommandItem (m, "Print...", bfp, VIB_MSG_PRINT);
4826 
4827     m = PulldownMenu (w, "Edit");
4828     FormCommandItem (m, COPY_MENU_ITEM, bfp, VIB_MSG_COPY);
4829 
4830     m = PulldownMenu (w, "Misc");
4831     sub = SubMenu (m, "Font Selection");
4832     i = CommandItem (sub, "Display Font...", DisplayFontChangeProc);
4833     SetObjectExtra (i, bfp, NULL);
4834     SeparatorItem (m);
4835     CreateLegendItem (m, bfp);
4836   }
4837 }
4838 
4839 /*==================================================================*/
4840 /*                                                                  */
4841 /*  SetupMenus () - Create and initialize the pulldown menus.       */
4842 /*                                                                  */
4843 /*==================================================================*/
4844 
SetupMenus(WindoW w)4845 static void SetupMenus (WindoW w)
4846 
4847 {
4848   BaseFormPtr  bfp;
4849   ChoicE       c;
4850   IteM         i;
4851   MenU         m;
4852   MenU         sub;
4853 
4854   bfp = (BaseFormPtr) GetObjectExtra (w);
4855   if (bfp != NULL) {
4856     m = PulldownMenu (w, "File");
4857     FormCommandItem (m, "Close", bfp, VIB_MSG_CLOSE);
4858     SeparatorItem (m);
4859     FormCommandItem (m, "Import...", bfp, VIB_MSG_IMPORT);
4860     FormCommandItem (m, "Export...", bfp, VIB_MSG_EXPORT);
4861     SeparatorItem (m);
4862     FormCommandItem (m, "Print...", bfp, VIB_MSG_PRINT);
4863 
4864     m = PulldownMenu (w, "Edit");
4865     FormCommandItem (m, COPY_MENU_ITEM, bfp, VIB_MSG_COPY);
4866 
4867     m = PulldownMenu (w, "Options");
4868     sub = SubMenu (m, "Neighbor Policy");
4869 
4870     c = CreateNeighborDelayChoice (sub, bfp);
4871     SeparatorItem (m);
4872     LoadDocsumOptionsMenu (m);
4873 
4874     m = PulldownMenu (w, "Misc");
4875     sub = SubMenu (m, "Font Selection");
4876     i = CommandItem (sub, "DocSum Font...", DocSumFontChangeProc);
4877     SetObjectExtra (i, bfp, NULL);
4878     i = CommandItem (sub, "Display Font...", DisplayFontChangeProc);
4879     SetObjectExtra (i, bfp, NULL);
4880   }
4881 }
4882 
4883 /*==================================================================*/
4884 /*                                                                  */
4885 /*  CreateDocsumForm () -                                           */
4886 /*                                                                  */
4887 /*==================================================================*/
4888 
CreateDocsumForm(Int2 left,Int2 top,CharPtr title,WndActnProc activate,FormMessageFunc messages,E2NamedUidListProc refineUidCallback,Boolean delayedNeighbor)4889 NLM_EXTERN ForM CreateDocsumForm (
4890   Int2 left,
4891   Int2 top,
4892   CharPtr title,
4893   WndActnProc activate,
4894   FormMessageFunc messages,
4895   E2NamedUidListProc refineUidCallback,
4896   Boolean delayedNeighbor
4897 )
4898 
4899 {
4900   ButtoN               b1, b2, b3;
4901   Entrez2GlobalsPtr    egp;
4902   Entrez2InfoPtr       e2ip;
4903   Entrez2DbInfoPtr     e2db;
4904   GrouP                g;
4905   GrouP                h;
4906   Int2                 j;
4907   GrouP                k;
4908   CharPtr PNTR         labels = defaultRadios;
4909   Boolean              macLike;
4910   PrompT               queryPrompt, launchPrompt, ppt1, ppt2;
4911   GrouP                q;
4912   Int2                 quarter;
4913   RecT                 r;
4914   Int2                 remaining;
4915   SummFormPtr          sfp;
4916   Int2                 typ_ml;
4917   WindoW               w = NULL;
4918   GrouP                x;
4919   GrouP                y;
4920   Int2                 dbKey;
4921   SeqViewProcsPtr      svpp;
4922   MedlineViewProcsPtr  mvpp;
4923 
4924   /*---------------------------------------*/
4925   /* Make connection to the Entrez2 server */
4926   /*---------------------------------------*/
4927 
4928   e2ip = Query_GetInfo ();
4929   if (e2ip == NULL) return NULL;
4930 
4931   /*----------------------------*/
4932   /* Get global config settings */
4933   /*----------------------------*/
4934 
4935   egp = (Entrez2GlobalsPtr) GetAppProperty ("Entrez2Globals");
4936   if (egp == NULL) return NULL;
4937   macLike = egp->popdownBehavior;
4938 
4939   /*----------------------------------*/
4940   /* Set up callbacks for SeqView and */
4941   /* MedlineView menus.               */
4942   /*----------------------------------*/
4943 
4944   svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
4945   /* create menus in window now also on Mac */
4946   svpp->createMenus = BioseqViewFormMenus_Callback;
4947   svpp->handleMessages = BioseqViewFormMessage_Callback;
4948 
4949   mvpp = (MedlineViewProcsPtr) GetAppProperty ("MedlineDisplayForm");
4950   /* create menus in window now also on Mac */
4951   mvpp->createMenus = MedlineViewFormMenus_Callback;
4952   mvpp->handleMessages = MedlineViewFormMessage_Callback;
4953 
4954   /*----------------------------------*/
4955   /* Create a data structure to store */
4956   /* data that we want to associate   */
4957   /* with the Document Summary window */
4958   /*----------------------------------*/
4959 
4960   sfp = (SummFormPtr) MemNew (sizeof (SummFormData));
4961   if (sfp == NULL) return (ForM) w;
4962 
4963   /*------------------------------------*/
4964   /* Create the document summary window */
4965   /*------------------------------------*/
4966 
4967   w = DocumentWindow (left, top, -10, -10, title, StdSendCloseWindowMessageProc, ResizeDocSumForm);
4968 
4969   /*-------------------------------*/
4970   /* Set window callback functions */
4971   /* and misc attributes.          */
4972   /*-------------------------------*/
4973 
4974   SetObjectExtra (w, sfp, CleanupEntrezDocSumForm);
4975   sfp->form = (ForM) w;
4976   sfp->formmessage = EntrezDocSumFormMessage_Callback;
4977   sfp->appmessage = messages;
4978 
4979   sfp->activate = activate;
4980   SetActivate (w, EntrezDocSumFormActivate_Callback);
4981 
4982   sfp->docsumFont = egp->docsumFont;
4983 
4984   if (sfp->docsumFont == NULL)
4985     sfp->docsumFont = programFont;
4986 
4987   sfp->refineUidProc = refineUidCallback;
4988   sfp->usingDelay = delayedNeighbor;
4989 
4990   /*-----------------------------------*/
4991   /* Set up the document summary menus */
4992   /*-----------------------------------*/
4993 
4994   SetupMenus (w);
4995 
4996   /*---------------------------------*/
4997   /* Set up the Format radio buttons */
4998   /*---------------------------------*/
4999 
5000   for (j = 0; j < MAX_DBS; j++) {
5001     sfp->formatPopups [j] = NULL;
5002     sfp->launchPopups [j] = NULL;
5003   }
5004 
5005   h = HiddenGroup (w, -1, 0, NULL);
5006   k = HiddenGroup (h, 4, 0, NULL);
5007   queryPrompt = StaticPrompt (k, "Format:", 0, 0, programFont, 'l');
5008   q = HiddenGroup (k, 0, 0, NULL);
5009 
5010   for (e2db = e2ip->db_info; e2db != NULL; e2db = e2db->next) {
5011     if (StringICmp (e2db->db_name, "PubMed") == 0)
5012       labels = medRadios;
5013     else if (StringICmp (e2db->db_name, "Protein") == 0)
5014       labels = prtRadios;
5015     else if (StringICmp (e2db->db_name, "Nucleotide") == 0)
5016       labels = nucRadios;
5017     else if (StringICmp (e2db->db_name, "nuccore") == 0)
5018       labels = nucRadios;
5019     else if (StringICmp (e2db->db_name, "Structure") == 0)
5020       labels = strucRadios;
5021     else if (StringICmp (e2db->db_name, "Genome") == 0)
5022       labels = genRadios;
5023     else if (StringICmp (e2db->db_name, "Popset") == 0)
5024       labels = popsetRadios;
5025     else if (StringICmp (e2db->db_name, "OMIM") == 0)
5026       labels = omimRadios;
5027     else if (StringICmp (e2db->db_name, "Taxonomy") == 0)
5028       labels = taxonomyRadios;
5029     else if (StringICmp (e2db->db_name, "Books") == 0)
5030       labels = bookRadios;
5031     else if (StringICmp (e2db->db_name, "geo") == 0)
5032       labels = probeRadios;
5033     else if (StringICmp (e2db->db_name, "domains") == 0)
5034       labels = domainRadios;
5035     else if (StringICmp (e2db->db_name, "unists") == 0)
5036       labels = stsRadios;
5037     else if (StringICmp (e2db->db_name, "cdd") == 0)
5038       labels = cddRadios;
5039     else if (StringICmp (e2db->db_name, "snp") == 0)
5040       labels = snpRadios;
5041     else if (StringICmp (e2db->db_name, "journals") == 0)
5042       labels = journalsRadios;
5043     else if (StringICmp (e2db->db_name, "unigene") == 0)
5044       labels = unigeneRadios;
5045     else if (StringICmp (e2db->db_name, "PMC") == 0)
5046       labels = pmcRadios;
5047     else if (StringICmp (e2db->db_name, "ncbisearch") == 0)
5048       labels = ncbisearchRadios;
5049     else if (StringICmp (e2db->db_name, "mesh") == 0)
5050       labels = meshRadios;
5051     else if (StringICmp (e2db->db_name, "gene") == 0)
5052       labels = geneRadios;
5053     else
5054       labels = defaultRadios;
5055 
5056     dbKey = DBGetIDFromName (e2db->db_name);
5057 
5058     sfp->formatPopups [dbKey] = PopupList (q, TRUE, ChangeFormat);
5059     SetObjectExtra (sfp->formatPopups [dbKey], sfp, NULL);
5060     for (j = 0; labels [j] != NULL; j++)
5061       PopupItem (sfp->formatPopups [dbKey], labels [j]);
5062     SetValue (sfp->formatPopups [dbKey], 1);
5063     Hide (sfp->formatPopups [dbKey]);
5064   }
5065 
5066   launchPrompt = StaticPrompt (k, "Double Click:", 0, 0, programFont, 'l');
5067   q = HiddenGroup (k, 0, 0, NULL);
5068 
5069 
5070   for (e2db = e2ip->db_info; e2db != NULL; e2db = e2db->next) {
5071     if (StringICmp (e2db->db_name, "PubMed") == 0)
5072       labels = medLaunch;
5073     else if (StringICmp (e2db->db_name, "Protein") == 0)
5074       labels = prtLaunch;
5075     else if (StringICmp (e2db->db_name, "Nucleotide") == 0)
5076       labels = nucLaunch;
5077     else if (StringICmp (e2db->db_name, "nuccore") == 0)
5078       labels = nucLaunch;
5079     else if (StringICmp (e2db->db_name, "Structure") == 0)
5080       labels = strucLaunch;
5081     else if (StringICmp (e2db->db_name, "Genome") == 0)
5082       labels = genLaunch;
5083     else if (StringICmp (e2db->db_name, "Popset") == 0)
5084       labels = popsetLaunch;
5085     else if (StringICmp (e2db->db_name, "OMIM") == 0)
5086       labels = omimLaunch;
5087     else if (StringICmp (e2db->db_name, "Taxonomy") == 0)
5088       labels = taxonomyLaunch;
5089     else if (StringICmp (e2db->db_name, "Books") == 0)
5090       labels = bookLaunch;
5091     else if (StringICmp (e2db->db_name, "geo") == 0)
5092       labels = probeLaunch;
5093     else if (StringICmp (e2db->db_name, "domains") == 0)
5094       labels = domainLaunch;
5095     else if (StringICmp (e2db->db_name, "unists") == 0)
5096       labels = stsLaunch;
5097     else if (StringICmp (e2db->db_name, "cdd") == 0)
5098       labels = cddLaunch;
5099     else if (StringICmp (e2db->db_name, "snp") == 0)
5100       labels = snpLaunch;
5101     else if (StringICmp (e2db->db_name, "journals") == 0)
5102       labels = journalsLaunch;
5103     else if (StringICmp (e2db->db_name, "unigene") == 0)
5104       labels = unigeneLaunch;
5105     else if (StringICmp (e2db->db_name, "PMC") == 0)
5106       labels = pmcLaunch;
5107     else if (StringICmp (e2db->db_name, "ncbisearch") == 0)
5108       labels = ncbisearchLaunch;
5109     else if (StringICmp (e2db->db_name, "mesh") == 0)
5110       labels = meshLaunch;
5111     else if (StringICmp (e2db->db_name, "gene") == 0)
5112       labels = geneLaunch;
5113     else
5114       labels = defaultLaunch;
5115 
5116     dbKey = DBGetIDFromName (e2db->db_name);
5117 
5118     sfp->launchPopups [dbKey] = PopupList (q, TRUE, NULL);
5119     SetObjectExtra (sfp->launchPopups [dbKey], sfp, NULL);
5120     for (j = 0; labels [j] != NULL; j++) {
5121       PopupItem (sfp->launchPopups [dbKey], labels [j]);
5122     }
5123     SetValue (sfp->launchPopups [dbKey], 1);
5124     Hide (sfp->launchPopups [dbKey]);
5125   }
5126 
5127   sfp->label = medRadios [0];
5128   AlignObjects (ALIGN_MIDDLE, (HANDLE) queryPrompt, (HANDLE) launchPrompt, (HANDLE) q, NULL);
5129   g = HiddenGroup (h, -1, 0, NULL);
5130   SetGroupSpacing (g, 5, 5);
5131 
5132   /*---------------------------*/
5133   /* Set up the document panel */
5134   /*---------------------------*/
5135 
5136   sfp->docsum = DocumentPanel (g, 33 * stdCharWidth, 20 * stdLineHeight);
5137   SetObjectExtra (sfp->docsum, sfp, NULL);
5138   SetDocProcs (sfp->docsum, ClickDocSum, NULL, ReleaseDocSum, NULL);
5139   SetDocCache (sfp->docsum, NULL, NULL, NULL);
5140   Hide (sfp->docsum);
5141 
5142   sfp->controls = HiddenGroup (g, 5, 0, NULL);
5143   SetGroupSpacing (sfp->controls, 10, 10);
5144 
5145   /*----------------------------------------*/
5146   /* Create the Neighbor and Refine buttons */
5147   /*----------------------------------------*/
5148 
5149   x = HiddenGroup (sfp->controls, 0, 2, NULL);
5150   sfp->retrieve = PushButton (x, "Neighbor 00000", RetrieveNeighbors);
5151   SetObjectExtra (sfp->retrieve, sfp, NULL);
5152   SetTitle (sfp->retrieve, "Neighbor 0");
5153   Disable (sfp->retrieve);
5154   sfp->refine = PushButton (x, "Refine 0000", RefineProc);
5155   SetObjectExtra (sfp->refine, sfp, NULL);
5156   SetTitle (sfp->refine, "Refine");
5157   Disable (sfp->refine);
5158   sfp->retrieveMode = FETCH_MODE;
5159 
5160   sfp->neighbors = NULL;
5161   sfp->numNeighbors = 0;
5162 
5163   sfp->historyFile = NULL;
5164   sfp->historyOffsets = NULL;
5165   sfp->generations = 0;
5166   sfp->present = 0;
5167 
5168   x = HiddenGroup (sfp->controls, 0, -3, NULL);
5169   SetGroupMargins (x, 3, 0);
5170   SetGroupSpacing (x, 3, 5);
5171 
5172   /*-------------------------------------*/
5173   /* Create a pulldown list of databases */
5174   /*-------------------------------------*/
5175 
5176   sfp->dbalist = CreateDatabaseAlist (e2ip);
5177 
5178   y = HiddenGroup (x, 5, 0, NULL);
5179   ppt1 = StaticPrompt (y, "Target:", 0, popupMenuHeight, programFont, 'l');
5180   sfp->target = PopupList (y, macLike, ChangeTarget);
5181   SetObjectExtra (sfp->target, sfp, NULL);
5182   InitEnumPopup (sfp->target, sfp->dbalist, NULL);
5183 
5184   typ_ml = DBGetIDFromName ("PubMed");
5185   SetEnumPopup (sfp->target, sfp->dbalist, (UIEnum) typ_ml);
5186 
5187   /*--------------------------*/
5188   /* Create selection buttons */
5189   /*--------------------------*/
5190 
5191   y = HiddenGroup (x, 4, 0, NULL);
5192   SetGroupSpacing (y, 8, 0);
5193   ppt2 = StaticPrompt (y, "Select:", 0, 0, programFont, 'l');
5194 
5195   b1 = PushButton (y, "All", SelectAllProc);
5196   SetObjectExtra (b1, sfp, NULL);
5197   b2 = PushButton (y, "None", ClearAllProc);
5198   SetObjectExtra (b2, sfp, NULL);
5199   b3 = PushButton (y, "Parents", SelectParentsProc);
5200   SetObjectExtra (b3, sfp, NULL);
5201 
5202   /*----------------------------------*/
5203   /* Set up Previous and Next buttons */
5204   /*----------------------------------*/
5205 
5206   x = HiddenGroup (sfp->controls, 0, 2, NULL);
5207 
5208   sfp->prevBtn = PushButton (x, "Prev", PrevButton_Callback);
5209   SetObjectExtra (sfp->prevBtn, sfp, NULL);
5210   Disable (sfp->prevBtn);
5211   sfp->nextBtn = PushButton (x, "Next", NextButton_Callback);
5212   SetObjectExtra (sfp->nextBtn, sfp, NULL);
5213   Disable (sfp->nextBtn);
5214 
5215   /*------------------------------------------*/
5216   /* Align the objects properly in the window */
5217   /*------------------------------------------*/
5218 
5219   AlignObjects (ALIGN_MIDDLE, (HANDLE) sfp->retrieve, (HANDLE) ppt1, (HANDLE) sfp->target, (HANDLE) sfp->prevBtn, NULL);
5220   AlignObjects (ALIGN_MIDDLE, (HANDLE) sfp->refine, (HANDLE) ppt2, (HANDLE) b1, (HANDLE) b2, (HANDLE) b3, (HANDLE) sfp->nextBtn, NULL);
5221 
5222   /*---------------------------------*/
5223   /* Calculate the size of the icons */
5224   /*---------------------------------*/
5225 
5226   RealizeWindow (w);
5227 
5228   SelectFont (programFont);
5229   sfp->lineHeight = LineHeight ();
5230   SelectFont (systemFont);
5231   sfp->linesPerIcon = (22 + sfp->lineHeight - 1) / sfp->lineHeight;
5232   docsumParFmt.minLines = sfp->linesPerIcon;
5233 
5234   /*---------------*/
5235   /*---------------*/
5236 
5237   ObjectRect (sfp->docsum, &r);
5238   InsetRect (&r, 4, 4);
5239   docsumColFmt [0].pixInset = 6 * stdCharWidth;
5240   remaining = r.right - r.left - 6 * stdCharWidth;
5241   quarter = remaining / 4;
5242   docsumColFmt [0].pixWidth = quarter + 6 * stdCharWidth;
5243   docsumColFmt [1].pixWidth = remaining - quarter;
5244   textColFmt [0].pixInset = 3 * stdCharWidth;
5245   textColFmt [0].pixWidth = screenRect.right - screenRect.left;
5246 
5247   SetDocAutoAdjust (sfp->docsum, FALSE);
5248 
5249   /*---------------------*/
5250   /* Return successfully */
5251   /*---------------------*/
5252 
5253   return (ForM) w;
5254 }
5255 
5256 
5257 /* NetConfig copied from old netcnfg.c file */
5258 
5259 typedef struct netconfigdata {
5260   FORM_MESSAGE_BLOCK
5261 
5262   GrouP           srvConnMode;
5263   GrouP           netGroup;
5264 
5265   TexT            proxyHost;
5266   TexT            proxyPort;
5267   TexT            firewallProxy;
5268 
5269   Char            proxyValue [256];
5270   Char            portValue [16];
5271   Char            firewallValue [256];
5272 
5273   ButtoN          dnsAvailable;
5274   PopuP           timeOut;
5275 
5276   VoidProc        accepted;
5277   VoidProc        cancelled;
5278   VoidProc        turnedOff;
5279 
5280   ButtoN          accept;
5281 } NetConfigData, PNTR NetConfigPtr;
5282 
ConfigMessageProc(ForM f,Int2 mssg)5283 static void ConfigMessageProc (ForM f, Int2 mssg)
5284 
5285 {
5286   VoidProc        cancelled;
5287   NetConfigPtr    ncp;
5288 
5289   ncp = (NetConfigPtr) GetObjectExtra (f);
5290   if (ncp != NULL) {
5291     switch (mssg) {
5292       case VIB_MSG_CLOSE:
5293         cancelled = ncp->cancelled;
5294         Remove (f);
5295         if (cancelled != NULL) {
5296           cancelled ();
5297         }
5298         break;
5299       case VIB_MSG_CUT:
5300         StdCutTextProc (NULL);
5301         break;
5302       case VIB_MSG_COPY:
5303         StdCopyTextProc (NULL);
5304         break;
5305       case VIB_MSG_PASTE:
5306         StdPasteTextProc (NULL);
5307         break;
5308       case VIB_MSG_DELETE:
5309         StdDeleteTextProc (NULL);
5310         break;
5311       default:
5312         if (ncp->appmessage != NULL) {
5313           ncp->appmessage (f, mssg);
5314         }
5315         break;
5316     }
5317   }
5318 }
5319 
ConfigFormActivate(WindoW w)5320 static void ConfigFormActivate (WindoW w)
5321 
5322 {
5323   NetConfigPtr    ncp;
5324 
5325   ncp = (NetConfigPtr) GetObjectExtra (w);
5326   if (ncp != NULL) {
5327     if (ncp->activate != NULL) {
5328       ncp->activate (w);
5329     }
5330   }
5331 }
5332 
NoEntryExists(CharPtr type)5333 static Boolean NoEntryExists (CharPtr type)
5334 
5335 {
5336   Char  str [256];
5337 
5338   if (GetAppParam ("NCBI", "NET_SERV", type, NULL, str, sizeof (str))) {
5339     if (! StringHasNoText (str)) return FALSE;
5340   }
5341   return TRUE;
5342 }
5343 
AcceptNetConfigForm(ButtoN b)5344 static void AcceptNetConfigForm (ButtoN b)
5345 
5346 {
5347   VoidProc      accepted;
5348   NetConfigPtr  ncp;
5349   Char          str [256];
5350   VoidProc      turnedOff;
5351   Int2          val;
5352 
5353   ncp = (NetConfigPtr) GetObjectExtra (b);
5354   if (ncp == NULL) return;
5355 
5356   val = GetValue (ncp->srvConnMode);
5357   if (val == 1) {
5358     turnedOff = ncp->turnedOff;
5359     Remove (ncp->form);
5360     if (turnedOff != NULL) {
5361       turnedOff ();
5362     }
5363     Update ();
5364     return;
5365   } else if (val == 3) {
5366     SetAppParam ("NCBI", "NET_SERV", "SRV_CONN_MODE", "SERVICE");
5367     SetAppParam ("NCBI", "NET_SERV", "FIREWALL", "TRUE");
5368     GetTitle (ncp->proxyHost, str, sizeof (str));
5369     if (! StringHasNoText (str)) {
5370       SetAppParam ("NCBI", "NET_SERV", "SRV_HTTP_PROXY_HOST", str);
5371       GetTitle (ncp->proxyPort, str, sizeof (str));
5372       if (StringICmp (str, "80") == 0) {
5373         str [0] = '\0';
5374       }
5375       if (! StringHasNoText (str)) {
5376         SetAppParam ("NCBI", "NET_SERV", "SRV_HTTP_PROXY_PORT", str);
5377       } else {
5378         SetAppParam ("NCBI", "NET_SERV", "SRV_HTTP_PROXY_PORT", NULL);
5379       }
5380     } else {
5381       SetAppParam ("NCBI", "NET_SERV", "SRV_HTTP_PROXY_HOST", NULL);
5382       SetAppParam ("NCBI", "NET_SERV", "SRV_HTTP_PROXY_PORT", NULL);
5383     }
5384     GetTitle (ncp->firewallProxy, str, sizeof (str));
5385     if (! StringHasNoText (str)) {
5386       SetAppParam ("NCBI", "NET_SERV", "SRV_PROXY_HOST", str);
5387     } else {
5388       SetAppParam ("NCBI", "NET_SERV", "SRV_PROXY_HOST", NULL);
5389     }
5390   } else {
5391     SetAppParam ("NCBI", "NET_SERV", "SRV_CONN_MODE", NULL);
5392     SetAppParam ("NCBI", "NET_SERV", "FIREWALL", NULL);
5393     SetAppParam ("NCBI", "NET_SERV", "SRV_HTTP_PROXY_HOST", NULL);
5394     SetAppParam ("NCBI", "NET_SERV", "SRV_HTTP_PROXY_PORT", NULL);
5395     SetAppParam ("NCBI", "NET_SERV", "SRV_PROXY_HOST", NULL);
5396   }
5397 
5398   if (GetStatus (ncp->dnsAvailable)) {
5399     SetAppParam ("NCBI", "NET_SERV", "SRV_ENGINE_HOST", NULL);
5400   } else {
5401     SetAppParam ("NCBI", "NET_SERV", "SRV_ENGINE_HOST", "130.14.22.106");
5402   }
5403 
5404   switch (GetValue (ncp->timeOut)) {
5405     case 1 :
5406       SetAppParam ("NCBI", "NET_SERV", "SRV_CONN_TIMEOUT", "10");
5407       break;
5408     case 3 :
5409       SetAppParam ("NCBI", "NET_SERV", "SRV_CONN_TIMEOUT", "60");
5410       break;
5411     case 4 :
5412       SetAppParam ("NCBI", "NET_SERV", "SRV_CONN_TIMEOUT", "300");
5413       break;
5414     default :
5415       SetAppParam ("NCBI", "NET_SERV", "SRV_CONN_TIMEOUT", NULL);
5416       break;
5417   }
5418 
5419   if (GetAppParam ("NCBI", "NET_SERV", "SRV_ENGINE_PORT", NULL, str, sizeof (str))) {
5420     if (StringICmp (str, "80") == 0) {
5421       SetAppParam ("NCBI", "NET_SERV", "SRV_ENGINE_PORT", NULL);
5422     }
5423   }
5424 
5425   if (GetAppParam ("NCBI", "NET_SERV", "SRV_ENGINE_URL", NULL, str, sizeof (str))) {
5426     if (StringICmp (str, "/Service/nph-dispd.cgi") == 0) {
5427       SetAppParam ("NCBI", "NET_SERV", "SRV_ENGINE_URL", NULL);
5428     }
5429   }
5430 
5431   if (NoEntryExists ("SRV_CONN_MODE") &&
5432       NoEntryExists ("FIREWALL") &&
5433       NoEntryExists ("SRV_CONN_TIMEOUT") &&
5434       NoEntryExists ("SRV_ENGINE_HOST") &&
5435       NoEntryExists ("SRV_ENGINE_PORT") &&
5436       NoEntryExists ("SRV_ENGINE_URL") &&
5437       NoEntryExists ("SRV_HTTP_PROXY_HOST") &&
5438       NoEntryExists ("SRV_HTTP_PROXY_PORT") &&
5439       NoEntryExists ("SRV_PROXY_HOST")) {
5440     SetAppParam ("NCBI", "NET_SERV", NULL, NULL);
5441   }
5442 
5443   accepted = ncp->accepted;
5444   Remove (ncp->form);
5445   if (accepted != NULL) {
5446     accepted ();
5447   }
5448   Update ();
5449 }
5450 
ChangeConfigControls(NetConfigPtr ncp)5451 static void ChangeConfigControls (NetConfigPtr ncp)
5452 
5453 {
5454   Boolean  hasProxy;
5455   Int2     val;
5456 
5457   if (ncp == NULL) return;
5458   val = GetValue (ncp->srvConnMode);
5459   if (val == 1) {
5460     SafeHide (ncp->netGroup);
5461   }
5462   if (val == 3) {
5463     if (! Enabled (ncp->proxyHost)) {
5464       SafeSetTitle (ncp->proxyHost, ncp->proxyValue);
5465     }
5466     Enable (ncp->proxyHost);
5467     if (! Enabled (ncp->firewallProxy)) {
5468       SafeSetTitle (ncp->firewallProxy, ncp->firewallValue);
5469     }
5470     Enable (ncp->firewallProxy);
5471   } else {
5472     if (Enabled (ncp->proxyHost)) {
5473       GetTitle (ncp->proxyHost, ncp->proxyValue, sizeof (ncp->proxyValue));
5474       SafeSetTitle (ncp->proxyHost, NULL);
5475     }
5476     Disable (ncp->proxyHost);
5477     if (Enabled (ncp->firewallProxy)) {
5478       GetTitle (ncp->firewallProxy, ncp->firewallValue, sizeof (ncp->firewallValue));
5479       SafeSetTitle (ncp->firewallProxy, NULL);
5480     }
5481     Disable (ncp->firewallProxy);
5482   }
5483   hasProxy = (Boolean) (! TextHasNoText (ncp->proxyHost));
5484   if (hasProxy) {
5485     if (! Enabled (ncp->proxyHost)) {
5486       SafeSetTitle (ncp->proxyHost, ncp->proxyValue);
5487     }
5488     Enable (ncp->proxyHost);
5489     if (! Enabled (ncp->proxyPort)) {
5490       SafeSetTitle (ncp->proxyPort, ncp->portValue);
5491     }
5492     Enable (ncp->proxyPort);
5493   } else {
5494     if (Enabled (ncp->proxyPort)) {
5495       GetTitle (ncp->proxyPort, ncp->portValue, sizeof (ncp->portValue));
5496       SafeSetTitle (ncp->proxyPort, NULL);
5497     }
5498     Disable (ncp->proxyPort);
5499   }
5500   if (val != 1) {
5501     SafeShow (ncp->netGroup);
5502   }
5503 }
5504 
ChangeConnection(GrouP g)5505 static void ChangeConnection (GrouP g)
5506 
5507 {
5508   NetConfigPtr  ncp;
5509 
5510   ncp = (NetConfigPtr) GetObjectExtra (g);
5511   ChangeConfigControls (ncp);
5512 }
5513 
ChangeProxy(TexT t)5514 static void ChangeProxy (TexT t)
5515 
5516 {
5517   NetConfigPtr  ncp;
5518 
5519   ncp = (NetConfigPtr) GetObjectExtra (t);
5520   ChangeConfigControls (ncp);
5521 }
5522 
ShowNewNetConfigForm(WndActnProc activate,FormMessageFunc messages,VoidProc accepted,VoidProc cancelled,VoidProc turnedOff,Boolean netCurrentlyOn)5523 NLM_EXTERN void ShowNewNetConfigForm (
5524   WndActnProc activate,
5525   FormMessageFunc messages,
5526   VoidProc accepted,
5527   VoidProc cancelled,
5528   VoidProc turnedOff,
5529   Boolean netCurrentlyOn
5530 )
5531 
5532 {
5533   ButtoN        b;
5534   GrouP         c;
5535   GrouP         g;
5536   GrouP         h;
5537   GrouP         j;
5538   Int2          len;
5539   NetConfigPtr  ncp;
5540   PrompT        ppt0, ppt1;
5541   ButtoN        rb;
5542   Char          str [256];
5543   WindoW        w;
5544   GrouP         x;
5545   GrouP         z;
5546 
5547   w = NULL;
5548   ncp = (NetConfigPtr) MemNew (sizeof (NetConfigData));
5549   if (ncp != NULL) {
5550 
5551     w = FixedWindow (-50, -33, -10, -10, "Network Configuration",
5552                      StdSendCloseWindowMessageProc);
5553     SetObjectExtra (w, ncp, StdCleanupFormProc);
5554     ncp->form = (ForM) w;
5555     ncp->formmessage = ConfigMessageProc;
5556 
5557     ncp->appmessage = messages;
5558     ncp->activate = activate;
5559     SetActivate (w, ConfigFormActivate);
5560 
5561     ncp->accepted = accepted;
5562     ncp->cancelled = cancelled;
5563     ncp->turnedOff = turnedOff;
5564 
5565     h = HiddenGroup (w, -1, 0, NULL);
5566     SetGroupSpacing (h, 5, 10);
5567 
5568     j = HiddenGroup (h, 2, 0, NULL);
5569     ppt0 = StaticPrompt (j, "Connection", 0, 0, programFont, 'l');
5570     ncp->srvConnMode = HiddenGroup (j, 4, 0, ChangeConnection);
5571     SetObjectExtra (ncp->srvConnMode, ncp, NULL);
5572     rb = RadioButton (ncp->srvConnMode, "None");
5573     RadioButton (ncp->srvConnMode, "Normal");
5574     RadioButton (ncp->srvConnMode, "Firewall");
5575     /* RadioButton (ncp->srvConnMode, "Stateless"); */
5576     SetValue (ncp->srvConnMode, 2);
5577     if (turnedOff == NULL) {
5578       Disable (rb);
5579     }
5580     AlignObjects (ALIGN_MIDDLE, (HANDLE) ppt0, (HANDLE) ncp->srvConnMode, NULL);
5581 
5582     ncp->netGroup = HiddenGroup (h, -1, 0, NULL);
5583     SetGroupSpacing (ncp->netGroup, 5, 10);
5584 
5585     SelectFont (programFont);
5586     len = StringWidth ("HTTP Proxy Server ") + 2;
5587     SelectFont (systemFont);
5588 
5589     z = HiddenGroup (ncp->netGroup, -2, 0, NULL);
5590     StaticPrompt (z, "HTTP Proxy Server", len, dialogTextHeight, programFont, 'l');
5591     ncp->proxyHost = DialogText (z, "", 12, ChangeProxy);
5592     SetObjectExtra (ncp->proxyHost, ncp, NULL);
5593     /*
5594     StaticPrompt (z, "", 0, 0, programFont, 'l');
5595     StaticPrompt (z, "", 0, 0, programFont, 'l');
5596     */
5597     ppt0 = StaticPrompt (z, "HTTP Proxy Port ", len, dialogTextHeight, programFont, 'l');
5598     ncp->proxyPort = DialogText (z, "", 3, NULL);
5599     x = MultiLinePrompt (z, "Non-transparent Proxy Server", len, programFont);
5600     ncp->firewallProxy = DialogText (z, "", 12, NULL);
5601     AlignObjects (ALIGN_MIDDLE, (HANDLE) x, (HANDLE) ncp->firewallProxy, NULL);
5602     /*
5603     AlignObjects (ALIGN_MIDDLE, (HANDLE) ppt0, (HANDLE) ncp->proxyPort,
5604                   (HANDLE) ncp->firewallProxy, NULL);
5605     */
5606     AlignObjects (ALIGN_RIGHT, (HANDLE) ncp->proxyHost, (HANDLE) ncp->firewallProxy, NULL);
5607     AlignObjects (ALIGN_LEFT, (HANDLE) ncp->proxyHost, (HANDLE) ncp->firewallProxy, NULL);
5608 
5609     g = HiddenGroup (ncp->netGroup, 5, 0, NULL);
5610     /*
5611     ppt0 = StaticPrompt (g, "Domain name server", 0, 0, programFont, 'l');
5612     ncp->dnsAvailable = CheckBox (g, "Available", NULL);
5613     */
5614     ncp->dnsAvailable = CheckBox (g, "Domain Name Server", NULL);
5615     SetStatus (ncp->dnsAvailable, TRUE);
5616     /* StaticPrompt (g, " ", 0, 0, programFont, 'l'); */
5617     ppt1 = StaticPrompt (g, "Timeout", 0, popupMenuHeight, programFont, 'l');
5618     ncp->timeOut = PopupList (g, TRUE, NULL);
5619     PopupItem (ncp->timeOut, "10 seconds");
5620     PopupItem (ncp->timeOut, "30 seconds");
5621     PopupItem (ncp->timeOut, "60 seconds");
5622     PopupItem (ncp->timeOut, " 5 minutes");
5623     SetValue (ncp->timeOut, 2);
5624     AlignObjects (ALIGN_MIDDLE, /* (HANDLE) ppt0, */ (HANDLE) ncp->dnsAvailable,
5625                   (HANDLE) ppt1, (HANDLE) ncp->timeOut, NULL);
5626 
5627     c = HiddenGroup (w, 4, 0, NULL);
5628     SetGroupSpacing (c, 10, 2);
5629     ncp->accept = PushButton (c, "Accept", AcceptNetConfigForm);
5630     SetObjectExtra (ncp->accept, ncp, NULL);
5631     b = PushButton (c, "Cancel", StdSendCancelButtonMessageProc);
5632     SetObjectExtra (b, ncp, NULL);
5633 
5634     /*
5635     AlignObjects (ALIGN_CENTER, (HANDLE) h, (HANDLE) c, NULL);
5636     */
5637     AlignObjects (ALIGN_CENTER, (HANDLE) j, (HANDLE) z, (HANDLE) g, (HANDLE) c, NULL);
5638 
5639     RealizeWindow (w);
5640 
5641     if (! netCurrentlyOn) {
5642       SafeSetValue (ncp->srvConnMode, 1);
5643       Hide (ncp->netGroup);
5644     } else if (GetAppParam ("NCBI", "NET_SERV", "SRV_CONN_MODE", "WWW", str, sizeof (str))) {
5645       if (StringICmp (str, "FIREWALL") == 0) {
5646         SafeSetValue (ncp->srvConnMode, 3);
5647       } else if (StringICmp (str, "SERVICE") == 0) {
5648         if (GetAppParam ("NCBI", "NET_SERV", "FIREWALL", "WWW", str, sizeof (str))) {
5649           if (StringICmp (str, "TRUE") == 0) {
5650             SafeSetValue (ncp->srvConnMode, 3);
5651           }
5652         }
5653       }
5654     }
5655     if (GetAppParam ("NCBI", "NET_SERV", "SRV_HTTP_PROXY_HOST", NULL, str, sizeof (str))) {
5656       if (! StringHasNoText (str)) {
5657         SafeSetTitle (ncp->proxyHost, str);
5658         if (GetValue (ncp->srvConnMode) == 2) {
5659           SafeSetValue (ncp->srvConnMode, 3);
5660         }
5661       }
5662     }
5663     if (GetAppParam ("NCBI", "NET_SERV", "SRV_HTTP_PROXY_PORT", NULL, str, sizeof (str))) {
5664       if (! StringHasNoText (str)) {
5665         SafeSetTitle (ncp->proxyPort, str);
5666       }
5667     }
5668     if (GetAppParam ("NCBI", "NET_SERV", "SRV_PROXY_HOST", NULL, str, sizeof (str))) {
5669       if (! StringHasNoText (str)) {
5670         SafeSetTitle (ncp->firewallProxy, str);
5671       }
5672     }
5673     if (GetAppParam ("NCBI", "NET_SERV", "SRV_ENGINE_HOST", NULL, str, sizeof (str))) {
5674       if (StringICmp (str, "130.14.22.106") == 0 || StringICmp (str, "130.14.22.107") == 0 ) {
5675         SafeSetStatus (ncp->dnsAvailable, FALSE);
5676       }
5677     }
5678     if (GetAppParam ("NCBI", "NET_SERV", "SRV_CONN_TIMEOUT", "30", str, sizeof (str))) {
5679       if (StringICmp (str, "10") == 0) {
5680         SafeSetValue (ncp->timeOut, 1);
5681       } else if (StringICmp (str, "60") == 0) {
5682         SafeSetValue (ncp->timeOut, 3);
5683       } else if (StringICmp (str, "300") == 0) {
5684         SafeSetValue (ncp->timeOut, 4);
5685       } else {
5686         SafeSetValue (ncp->timeOut, 2);
5687       }
5688     }
5689 
5690     ChangeConfigControls (ncp);
5691 
5692     Show (w);
5693     Select (w);
5694     Select (ncp->proxyHost);
5695   }
5696 }
5697 
5698