~ubuntu-branches/ubuntu/breezy/ncbi-tools6/breezy

« back to all changes in this revision

Viewing changes to desktop/e2docsum.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2002-04-04 22:13:09 UTC
  • Revision ID: james.westby@ubuntu.com-20020404221309-vfze028rfnlrldct
Tags: upstream-6.1.20011220a
ImportĀ upstreamĀ versionĀ 6.1.20011220a

Show diffs side-by-side

added added

removed removed

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