1 /*   bspview.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:  bspview.c
27 *
28 * Author:  Jonathan Kans
29 *
30 * Version Creation Date:   4/30/95
31 *
32 * $Revision: 6.176 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date     Name        Description of modification
39 * -------  ----------  -----------------------------------------------------
40 *
41 *
42 * ==========================================================================
43 */
44 
45 #include <bspview.h>
46 #include <document.h>
47 #include <picture.h>
48 #include <viewer.h>
49 #include <drawseq.h>
50 #include <objfdef.h>
51 #include <gather.h>
52 #include <subutil.h>
53 #include <asn2ff.h>
54 #include <tofasta.h>
55 #include <txalign.h>
56 #include <fstyle.h>
57 #include <picturep.h>
58 #include <drawingp.h>
59 #include <viewerp.h>
60 #include <objentr.h>
61 #include <accentr.h>
62 #include <mapgene.h>
63 #include <saledit.h>
64 #include <fea2seg.h>
65 #include <blast.h>
66 #include <blastpri.h>
67 #include <explore.h>
68 #include <asn2graphic.h>
69 #include <seqpanel.h>
70 #include <vsm.h>
71 #include <objmgr.h>
72 /*
73 #include <udviewer.h>
74 #include <udvdef.h>
75 #include <udvseq.h>
76 #include <ddvmain.h>
77 #include <ddvpanel.h>
78 #include <ddvgraph.h>
79 */
80 #ifdef WIN_MOTIF
81 #include <netscape.h>
82 #endif
83 
84 #define NLM_GENERATED_CODE_PROTO
85 #include <objmacro.h>
86 #include <macroapi.h>
87 
88 extern ForM smartBioseqViewForm;
89 ForM smartBioseqViewForm = NULL;
90 
91 #define MAX_VIEWABLE_TARGET_SEQUENCES 32768
92 
LookForGenomeTag(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)93 static void LookForGenomeTag (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
94 
95 {
96   BioseqPtr      bsp;
97   BioseqSetPtr   bssp;
98   ValNodePtr     descr;
99   BoolPtr        rsltptr;
100   UserObjectPtr  uop;
101 
102   rsltptr = (BoolPtr) mydata;
103   if (rsltptr == NULL) return;
104   descr = NULL;
105   if (IS_Bioseq (sep)) {
106     bsp = (BioseqPtr) sep->data.ptrvalue;
107     descr = bsp->descr;
108   } else if (IS_Bioseq_set (sep)) {
109     bssp = (BioseqSetPtr) sep->data.ptrvalue;
110     descr = bssp->descr;
111   } else return;
112   while (descr != NULL) {
113     if (descr->choice == Seq_descr_user) {
114       uop = (UserObjectPtr) descr->data.ptrvalue;
115       if (uop != NULL && StringICmp (uop->_class, "Genomes") == 0) {
116         *rsltptr = TRUE;
117       }
118     }
119     descr = descr->next;
120   }
121 }
122 
IsAGenomeRecord(SeqEntryPtr sep)123 extern Boolean LIBCALL IsAGenomeRecord (SeqEntryPtr sep)
124 
125 {
126   Boolean  rsult;
127 
128   rsult = FALSE;
129   SeqEntryExplore (sep, &rsult, LookForGenomeTag);
130   /*
131   if (FindBioseqSetByClass (sep, BioseqseqSet_class_nuc_prot) != NULL) {
132     rsult = FALSE;
133   }
134   */
135   return rsult;
136 }
137 
138 typedef struct updatesegstruc {
139   BioseqSetPtr      parts;
140   BioseqPtr         segseq;
141   BioseqSetPtr      segset;
142 } UpdateSegStruc, PNTR UpdateSegStrucPtr;
143 
FindSegSetComponentsCallback(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)144 static void FindSegSetComponentsCallback (SeqEntryPtr sep, Pointer mydata,
145                                           Int4 index, Int2 indent)
146 
147 {
148   BioseqPtr          bsp;
149   BioseqSetPtr       bssp;
150   UpdateSegStrucPtr  ussp;
151 
152   if (sep != NULL && sep->data.ptrvalue && mydata != NULL) {
153     ussp = (UpdateSegStrucPtr) mydata;
154     if (sep->choice == 1) {
155       bsp = (BioseqPtr) sep->data.ptrvalue;
156       if (ISA_na (bsp->mol) && bsp->repr == Seq_repr_seg) {
157         ussp->segseq = bsp;
158       }
159     } else if (sep->choice == 2) {
160       bssp = (BioseqSetPtr) sep->data.ptrvalue;
161       if (bssp->_class == 2) {
162         ussp->segset = bssp;
163       } else if (bssp->_class == 4) {
164         ussp->parts = bssp;
165       }
166     }
167   }
168 }
169 
UpdateSegList(SeqEntryPtr sep,Pointer mydata,SeqEntryFunc mycallback,Int4 index,Int2 indent)170 static Int4 UpdateSegList (SeqEntryPtr sep, Pointer mydata,
171                            SeqEntryFunc mycallback,
172                            Int4 index, Int2 indent)
173 
174 {
175   BioseqSetPtr  bssp;
176 
177   if (sep == NULL) return index;
178   if (mycallback != NULL)
179     (*mycallback) (sep, mydata, index, indent);
180   index++;
181   if (IS_Bioseq (sep)) return index;
182   if (Bioseq_set_class (sep) == 4) return index;
183   bssp = (BioseqSetPtr) sep->data.ptrvalue;
184   sep = bssp->seq_set;
185   indent++;
186   while (sep != NULL) {
187     index = UpdateSegList (sep, mydata, mycallback, index, indent);
188     sep = sep->next;
189   }
190   return index;
191 }
192 
193 #define UpdateSegExplore(a,b,c) UpdateSegList(a, b, c, 0L, 0);
194 
IsSegmentedBioseqWithoutParts(SeqEntryPtr sep)195 extern Boolean IsSegmentedBioseqWithoutParts (SeqEntryPtr sep)
196 
197 {
198   UpdateSegStruc  uss;
199 
200   if (sep == NULL) return FALSE;
201   uss.segseq = NULL;
202   uss.parts = NULL;
203   uss.segset = NULL;
204   UpdateSegExplore (sep, (Pointer) &uss, FindSegSetComponentsCallback);
205   if (uss.segseq != NULL && uss.parts == NULL) return TRUE;
206   return FALSE;
207 }
208 
LookForDeltaBioseq(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)209 static void LookForDeltaBioseq (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
210 
211 {
212   BioseqPtr  bsp;
213   BoolPtr    rsltptr;
214 
215   rsltptr = (BoolPtr) mydata;
216   if (rsltptr == NULL) return;
217   if (IS_Bioseq (sep)) {
218     bsp = (BioseqPtr) sep->data.ptrvalue;
219     if (bsp != NULL && bsp->repr == Seq_repr_delta) {
220       *rsltptr = TRUE;
221     }
222   }
223 }
224 
IsADeltaBioseq(SeqEntryPtr sep)225 extern Boolean IsADeltaBioseq (SeqEntryPtr sep)
226 
227 {
228   Boolean  rsult;
229 
230   rsult = FALSE;
231   SeqEntryExplore (sep, &rsult, LookForDeltaBioseq);
232   return rsult;
233 }
234 
get_db_sip(SeqFeatPtr sfp)235 static SeqIdPtr get_db_sip (SeqFeatPtr sfp)
236 {
237     GeneRefPtr grp;
238     ValNodePtr db;
239     DbtagPtr db_tag;
240     ObjectIdPtr obj_id;
241     CharPtr acc;
242 
243     if (sfp == NULL || sfp->data.choice != SEQFEAT_GENE) return NULL;
244     grp = sfp->data.value.ptrvalue;
245     if (grp == NULL) return NULL;
246     for (db=grp->db; db!=NULL; db=db->next)
247     {
248         db_tag = db->data.ptrvalue;
249         if(StringICmp(db_tag->db, "GenBank") == 0)
250         {
251             obj_id = db_tag->tag;
252             acc = obj_id->str;
253             return gb_id_make(NULL, acc);
254         }
255     }
256 
257     return NULL;
258 }
259 
NamedAlignmentProc(GatherContextPtr gcp)260 static Boolean NamedAlignmentProc (GatherContextPtr gcp)
261 
262 {
263   AnnotDescrPtr  adp;
264   Uint1          extra_type;
265   ObjectIdPtr    oip;
266   BoolPtr        rsult;
267   SeqAnnotPtr    sap;
268   SeqFeatPtr     sfp;
269   SeqIdPtr       sip;
270   UserObjectPtr  uop;
271 
272   if (gcp == NULL || gcp->thisitem == NULL) {
273     return FALSE;
274   }
275   rsult = (BoolPtr) gcp->userdata;
276   if (rsult == NULL) return FALSE;
277   switch (gcp->thistype) {
278     case OBJ_SEQALIGN :
279     case OBJ_SEQHIST_ALIGN :
280       if (gcp->parenttype == OBJ_SEQANNOT) {
281         sap = (SeqAnnotPtr) gcp->parentitem;
282         if (sap != NULL) {
283           adp = sap->desc;
284           while (adp != NULL) {
285             if (adp->choice == Annot_descr_user) {
286               uop = (UserObjectPtr) adp->data.ptrvalue;
287               if (uop != NULL) {
288                 oip = uop->type;
289                 if (oip != NULL) {
290                   if (StringICmp (oip->str, "Hist Seqalign") == 0) {
291                     *rsult = TRUE;
292                   }
293                 }
294               }
295             }
296             adp = adp->next;
297           }
298         }
299       }
300       return TRUE;
301     case OBJ_BIOSEQ_MAPFEAT :
302       sfp = (SeqFeatPtr) gcp->thisitem;
303       extra_type = ck_seqfeat_extra (sfp);
304       if (extra_type & EXTRA_GENBANK)
305       {
306         sip = get_db_sip (sfp);
307         if (sip != NULL) {
308           *rsult = TRUE;
309         }
310         SeqIdFree (sip);
311         return TRUE;
312       }
313       break;
314     default :
315       break;
316   }
317   return FALSE;
318 }
319 
IsANamedAlignment(Uint2 entityID,Uint4 itemID,Uint2 itemtype)320 extern Boolean LIBCALL IsANamedAlignment (Uint2 entityID, Uint4 itemID, Uint2 itemtype)
321 
322 {
323   Boolean  rsult;
324 
325   rsult = FALSE;
326   GatherItem (entityID, itemID, itemtype, (Pointer) (&rsult), NamedAlignmentProc);
327   return rsult;
328 }
329 
LaunchViewerNotEditor(BioseqViewPtr bvp,SeqEntryPtr sep,Uint2 entityID,Uint4 itemID,Uint2 itemtype)330 extern Boolean LIBCALL LaunchViewerNotEditor (BioseqViewPtr bvp, SeqEntryPtr sep,
331                                               Uint2 entityID, Uint4 itemID, Uint2 itemtype)
332 
333 {
334   if (bvp == NULL) return FALSE;
335   if (! bvp->launchEditors) return FALSE;
336   if (IsAGenomeRecord (sep) ||
337       IsSegmentedBioseqWithoutParts (sep) ||
338       IsADeltaBioseq (sep) ||
339       IsANamedAlignment (entityID, itemID, itemtype)) {
340     if (itemtype == OBJ_BIOSEQ_SEG || itemtype == OBJ_BIOSEQ_DELTA ||
341         itemtype == OBJ_SEQALIGN || itemtype == OBJ_SEQHIST_ALIGN ||
342         itemtype == OBJ_BIOSEQ_MAPFEAT) {
343       return TRUE;
344     }
345   }
346   return FALSE;
347 }
348 
AddOneBlastAlignment(BioseqPtr subject,BioseqPtr query)349 static void AddOneBlastAlignment (BioseqPtr subject, BioseqPtr query)
350 
351 {
352   Uint1                align_type = 0;
353   BioseqPtr            bsp;
354   BioseqSetPtr         bssp;
355   SeqAnnotPtr          curr;
356   BLAST_OptionsBlkPtr  options = NULL;
357   SeqAlignPtr          prev;
358   CharPtr              program_name = NULL;
359   SeqAlignPtr          salp;
360   SeqAnnotPtr          sap;
361   SeqAnnotPtr PNTR     sapp;
362   BlastSearchBlkPtr    search;
363   SeqEntryPtr          sep;
364 
365   if (subject == NULL || query == NULL) return;
366   sap = NULL;
367   salp = NULL;
368   if (ISA_na (subject->mol)) {
369     if (! ISA_na (query->mol)) return;
370     align_type = 1;
371     program_name = "blastn";
372     options = BLASTOptionNew (program_name, TRUE);
373     if (options != NULL) {
374       options->gapped_calculation = TRUE;
375       options->db_length = 100000000;
376 #ifdef WIN16
377       options->wordsize = 10;
378 #else
379       options->wordsize = 12;
380 #endif
381     }
382   } else if (ISA_aa (subject->mol)) {
383     if (! ISA_aa (query->mol)) return;
384     align_type = 2;
385     program_name = "blastp";
386     options = BLASTOptionNew (program_name, TRUE);
387     if (options != NULL) {
388       options->gapped_calculation = TRUE;
389       options->db_length = 20000000;
390       options->threshold_second = 12;
391     }
392   } else return;
393   search = BLASTSetUpSearch (subject, program_name, 0, 0, NULL, options, NULL);
394 
395   salp = BlastSequencesOnTheFly (search, query);
396   if (salp != NULL) {
397     if (sap == NULL) {
398       sap = SeqAnnotNew ();
399       if (sap != NULL) {
400         sap->type = 2;
401       }
402     }
403     if (sap != NULL) {
404       if (sap->data != NULL) {
405         prev = sap->data;
406         while (prev->next != NULL) {
407           prev = prev->next;
408         }
409         prev->next = salp;
410       } else {
411         sap->data = (Pointer) salp;
412       }
413     }
414   }
415 
416   BLASTOptionDelete (options);
417   BlastSearchBlkDestruct (search);
418 
419   if (sap == NULL) return;
420 
421   AddAlignInfoToSeqAnnot (sap, align_type);
422   /*
423   ObjMgrRegister (OBJ_SEQANNOT, (Pointer) sap);
424   */
425   sapp = NULL;
426   sep = SeqMgrGetSeqEntryForData (subject);
427   if (IS_Bioseq (sep)) {
428     bsp = (BioseqPtr) sep->data.ptrvalue;
429     sapp = &(bsp->annot);
430   } else if (IS_Bioseq_set (sep)) {
431     bssp = (BioseqSetPtr) sep->data.ptrvalue;
432     sapp = &(bssp->annot);
433   }
434   if (sapp != NULL) {
435     if (*sapp != NULL) {
436       curr = *sapp;
437       while (curr->next != NULL) {
438         curr = curr->next;
439       }
440       curr->next = sap;
441     } else {
442       *sapp = sap;
443     }
444   }
445 }
446 
LaunchSequenceViewer(SeqIdPtr sip,BioseqPtr query)447 static Boolean LaunchSequenceViewer (SeqIdPtr sip, BioseqPtr query)
448 
449 {
450   BioseqPtr        bsp;
451   Uint2            entityID;
452   Int2             handled;
453   Uint4            itemID;
454   SeqViewProcsPtr  svpp;
455 
456   if (sip == NULL) return FALSE;
457   SeqEntrySetScope (NULL);
458   bsp = BioseqLockById (sip);
459   if (bsp == NULL) return FALSE;
460   SeqEntrySetScope (NULL);
461   entityID = BioseqFindEntity (sip, &itemID);
462   if (entityID == 0) return FALSE;
463   WatchCursor ();
464   svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
465   if (svpp != NULL) {
466     svpp->forceSeparateViewer = TRUE;
467     if (query != NULL && query->repr == Seq_repr_raw && query->length < 100000 &&
468         bsp->repr == Seq_repr_raw && bsp->length < 100000) {
469       if (svpp->alignWithChecked != NULL) {
470         if (GetStatus (svpp->alignWithChecked)) {
471           AddOneBlastAlignment (bsp, query);
472         }
473       } else if (svpp->alignDefault) {
474         AddOneBlastAlignment (bsp, query);
475       }
476     }
477   }
478   handled = GatherProcLaunch (OMPROC_VIEW, FALSE, entityID, itemID,
479                               OBJ_BIOSEQ, 0, 0, OBJ_BIOSEQ, 0);
480   ArrowCursor ();
481   if (handled != OM_MSG_RET_DONE || handled == OM_MSG_RET_NOPROC) {
482     Message (MSG_FATAL, "Unable to launch viewer.");
483   } else {
484     ObjMgrSetOptions (OM_OPT_FREE_IF_NO_VIEW, entityID);
485   }
486   BioseqUnlockById (sip);
487 
488   return TRUE;
489 }
490 
LaunchPrim(GatherContextPtr gcp)491 static Boolean LaunchPrim (GatherContextPtr gcp)
492 
493 {
494   SeqAlignPtr   align;
495   BioseqPtr     bsp;
496   DenseDiagPtr  ddp;
497   DeltaSeqPtr   delsp;
498   DenseSegPtr   dsp;
499   Uint1         extra_type;
500   SeqLocPtr     seg_loc;
501   SeqFeatPtr    sfp;
502   SeqIdPtr      sip;
503   SeqLocPtr     slp;
504   StdSegPtr     ssp;
505 /* SeqLocPtr     tloc; */
506   ValNode       vn;
507 
508   if (gcp == NULL || gcp->thisitem == NULL) {
509     Beep ();
510     return FALSE;
511   }
512   bsp = (BioseqPtr) gcp->userdata;
513   if (bsp == NULL) return FALSE;
514   vn.choice = SEQLOC_WHOLE;
515   vn.data.ptrvalue = (Pointer) bsp->id;
516   slp = &vn;
517   switch (gcp->thistype) {
518     case OBJ_BIOSEQ_SEG :
519       seg_loc = (SeqLocPtr) gcp->thisitem;
520       sip = SeqLocId (seg_loc);
521       if (! LaunchSequenceViewer (sip, bsp)) {
522         Beep ();
523         return FALSE;
524       }
525       return TRUE;
526     case OBJ_BIOSEQ_DELTA :
527       delsp = (DeltaSeqPtr) gcp->thisitem;
528       if (delsp != NULL && delsp->choice == 1) {
529         seg_loc = (SeqLocPtr) delsp->data.ptrvalue;
530         sip = SeqLocId (seg_loc);
531         if (! LaunchSequenceViewer (sip, bsp)) {
532           Beep ();
533           return FALSE;
534         }
535       }
536       return TRUE;
537     case OBJ_SEQALIGN :
538     case OBJ_SEQHIST_ALIGN :
539       align = (SeqAlignPtr) gcp->thisitem;
540       sip = NULL;
541       if (align->segtype == 1) {
542         ddp = (DenseDiagPtr) align->segs;
543         if (ddp != NULL) {
544           for (sip = ddp->id; sip != NULL; sip = sip->next) {
545             if (! SeqIdForSameBioseq (sip, SeqLocId (slp)))
546               break;
547           }
548         }
549       } else if (align->segtype == 2) {
550         dsp = (DenseSegPtr) align->segs;
551         if (dsp != NULL) {
552           if (dsp->ids != NULL) {
553             sip = dsp->ids->next;
554           }
555           /*
556           for (sip = dsp->ids; sip != NULL; sip = sip->next) {
557             if (! SeqIdForSameBioseq (sip, SeqLocId (slp)))
558               break;
559           }
560           */
561         }
562       } else if (align->segtype == 3) {
563         ssp = (StdSegPtr) align->segs;
564         if (ssp != NULL && ssp->loc != NULL) {
565           if (ssp->loc->next != NULL) {
566             sip = SeqLocId (ssp->loc->next);
567           }
568           /*
569           for (tloc = ssp->loc; tloc != NULL; tloc = tloc->next) {
570             if (! SeqIdForSameBioseq (SeqLocId (tloc), SeqLocId (slp))) {
571               sip = SeqLocId (tloc);
572               break;
573             }
574           }
575           */
576         }
577       }
578       if (sip != NULL) {
579         if (! LaunchSequenceViewer (sip, bsp)) {
580           Beep ();
581           return FALSE;
582         }
583       }
584       return TRUE;
585     case OBJ_BIOSEQ_MAPFEAT :
586       sfp = (SeqFeatPtr) gcp->thisitem;
587       extra_type = ck_seqfeat_extra (sfp);
588       if (extra_type & EXTRA_GENBANK)
589       {
590         sip = get_db_sip (sfp);
591         if (! LaunchSequenceViewer (sip, bsp)) {
592           SeqIdFree (sip);
593           Beep ();
594           return FALSE;
595         }
596         SeqIdFree (sip);
597         return TRUE;
598       }
599       if (sfp->product != NULL) {
600         sip = SeqLocId (sfp->product);
601         if (sip != NULL) {
602           if (! LaunchSequenceViewer (sip, bsp)) {
603             Beep ();
604             return FALSE;
605           }
606         }
607       }
608       break;
609     default :
610       break;
611   }
612   return FALSE;
613 }
614 
LaunchNewBioseqViewer(BioseqPtr bsp,Uint2 entityID,Uint4 itemID,Uint2 itemtype)615 void LIBCALL LaunchNewBioseqViewer (BioseqPtr bsp, Uint2 entityID, Uint4 itemID, Uint2 itemtype)
616 
617 {
618   GatherItem (entityID, itemID, itemtype, (Pointer) bsp, LaunchPrim);
619 }
620 
AddBioseqPageToList(BioseqPagePtr PNTR head,BioseqPagePtr bpp)621 extern void LIBCALL AddBioseqPageToList (BioseqPagePtr PNTR head, BioseqPagePtr bpp)
622 
623 {
624   BioseqPagePtr  newbpp;
625   BioseqPagePtr  tmpbpp;
626 
627   if (head == NULL || bpp == NULL) return;
628   newbpp = MemNew (sizeof (BioseqPageData));
629   if (newbpp == NULL) return;
630   if (*head != NULL) {
631     tmpbpp = *head;
632     while (tmpbpp->next != NULL) {
633       tmpbpp = tmpbpp->next;
634     }
635     tmpbpp->next = newbpp;
636   } else {
637     *head = newbpp;
638   }
639   newbpp->label = StringSaveNoNull (bpp->label);
640   newbpp->nucOK = bpp->nucOK;
641   newbpp->protOK = bpp->protOK;
642   newbpp->genomeOK = bpp->genomeOK;
643   newbpp->needAlignment = bpp->needAlignment;
644   newbpp->maxLength = bpp->maxLength;
645   newbpp->populate = bpp->populate;
646   newbpp->show = bpp->show;
647   newbpp->highlight = bpp->highlight;
648   newbpp->toClipboard = bpp->toClipboard;
649   newbpp->print = bpp->print;
650   newbpp->exprt = bpp->exprt;
651   newbpp->togif = bpp->togif;
652   newbpp->resize = bpp->resize;
653   newbpp->next = NULL;
654 }
655 
BioseqPageListFree(BioseqPagePtr bpp)656 extern BioseqPagePtr LIBCALL BioseqPageListFree (BioseqPagePtr bpp)
657 
658 {
659   BioseqPagePtr  next;
660 
661   while (bpp != NULL) {
662     next = bpp->next;
663     bpp->label = MemFree (bpp->label);
664     MemFree (bpp);
665     bpp = next;
666   }
667   return NULL;
668 }
669 
LookInSeqIdList(SeqIdPtr sip,ValNodePtr PNTR vnpp,Uint1 align_type,Boolean useUids)670 static void LookInSeqIdList (SeqIdPtr sip, ValNodePtr PNTR vnpp, Uint1 align_type, Boolean useUids)
671 
672 {
673   Char  str [64];
674   BIG_ID  uid;
675 
676   while (sip != NULL) {
677     switch (sip->choice) {
678       case SEQID_NOT_SET :
679       case SEQID_LOCAL :
680         break;
681       case SEQID_GI :
682         if (useUids) {
683           uid = (BIG_ID) sip->data.intvalue;
684           ValNodeAddInt (vnpp, align_type, uid);
685         } else {
686           SeqIdWrite (sip, str, PRINTID_REPORT, sizeof (str));
687           ValNodeCopyStr (vnpp, align_type, str);
688         }
689         break;
690       default :
691         if (useUids) {
692           uid = GetGIForSeqId (sip);
693           if (uid > 0) {
694             ValNodeAddInt (vnpp, align_type, uid);
695           }
696         } else {
697           SeqIdWrite (sip, str, PRINTID_REPORT, sizeof (str));
698           ValNodeCopyStr (vnpp, align_type, str);
699         }
700         break;
701     }
702     sip = sip->next;
703   }
704 }
705 
LookInSeqLocList(SeqLocPtr slp,ValNodePtr PNTR vnpp,Uint1 align_type,Boolean useUids)706 static void LookInSeqLocList (SeqLocPtr slp, ValNodePtr PNTR vnpp, Uint1 align_type, Boolean useUids)
707 
708 {
709   SeqLocPtr      loc;
710   PackSeqPntPtr  psp;
711   SeqBondPtr     sbp;
712   SeqIntPtr      sinp;
713   SeqIdPtr       sip;
714   SeqPntPtr      spp;
715 
716   while (slp != NULL) {
717     switch (slp->choice) {
718       case SEQLOC_NULL :
719         break;
720       case SEQLOC_EMPTY :
721       case SEQLOC_WHOLE :
722         sip = (SeqIdPtr) slp->data.ptrvalue;
723         LookInSeqIdList (sip, vnpp, align_type, useUids);
724         break;
725       case SEQLOC_INT :
726         sinp = (SeqIntPtr) slp->data.ptrvalue;
727         if (sinp != NULL) {
728           sip = sinp->id;
729           LookInSeqIdList (sip, vnpp, align_type, useUids);
730         }
731         break;
732       case SEQLOC_PNT :
733         spp = (SeqPntPtr) slp->data.ptrvalue;
734         if (spp != NULL) {
735           sip = spp->id;
736           LookInSeqIdList (sip, vnpp, align_type, useUids);
737         }
738         break;
739       case SEQLOC_PACKED_PNT :
740         psp = (PackSeqPntPtr) slp->data.ptrvalue;
741         if (psp != NULL) {
742           sip = psp->id;
743           LookInSeqIdList (sip, vnpp, align_type, useUids);
744         }
745         break;
746       case SEQLOC_PACKED_INT :
747       case SEQLOC_MIX :
748       case SEQLOC_EQUIV :
749         loc = (SeqLocPtr) slp->data.ptrvalue;
750         while (loc != NULL) {
751           LookInSeqIdList (loc, vnpp, align_type, useUids);
752           loc = loc->next;
753         }
754         break;
755       case SEQLOC_BOND :
756         sbp = (SeqBondPtr) slp->data.ptrvalue;
757         if (sbp != NULL) {
758           spp = (SeqPntPtr) sbp->a;
759           if (spp != NULL) {
760             sip = spp->id;
761             LookInSeqIdList (sip, vnpp, align_type, useUids);
762           }
763           spp = (SeqPntPtr) sbp->b;
764           if (spp != NULL) {
765             sip = spp->id;
766             LookInSeqIdList (sip, vnpp, align_type, useUids);
767           }
768         }
769         break;
770       case SEQLOC_FEAT :
771         break;
772       default :
773         break;
774     }
775     slp = slp->next;
776   }
777 }
778 
GetSeqIdsForOneSeqAnnot(SeqAnnotPtr sap,ValNodePtr PNTR vnpp,Uint1 align_type,Boolean useUids)779 static void LIBCALL GetSeqIdsForOneSeqAnnot (SeqAnnotPtr sap, ValNodePtr PNTR vnpp, Uint1 align_type, Boolean useUids)
780 
781 {
782   DenseDiagPtr   ddp;
783   DenseSegPtr    dsp;
784   SeqAlignPtr    sal;
785   StdSegPtr      ssp;
786 
787   if (sap == NULL || vnpp == NULL) return;
788   if (sap->type == 2) {
789     sal = (SeqAlignPtr) sap->data;
790     while (sal != NULL) {
791       if (sal->segtype == 1) {
792         ddp = (DenseDiagPtr) sal->segs;
793         if (ddp != NULL) {
794           LookInSeqIdList (ddp->id, vnpp, align_type, useUids);
795         }
796       } else if (sal->segtype == 2) {
797         dsp = (DenseSegPtr) sal->segs;
798         if (dsp != NULL) {
799           LookInSeqIdList (dsp->ids, vnpp, align_type, useUids);
800         }
801       } else if (sal->segtype == 3) {
802         ssp = (StdSegPtr) sal->segs;
803         if (ssp != NULL) {
804            LookInSeqLocList (ssp->loc, vnpp, align_type, useUids);
805         }
806       }
807       sal = sal->next;
808     }
809   }
810 }
811 
GetUidsForOneSeqAnnot(SeqAnnotPtr sap,ValNodePtr PNTR vnpp,Uint1 align_type)812 extern void LIBCALL GetUidsForOneSeqAnnot (SeqAnnotPtr sap, ValNodePtr PNTR vnpp, Uint1 align_type)
813 
814 {
815   GetSeqIdsForOneSeqAnnot (sap, vnpp, align_type, TRUE);
816 }
817 
GetAlignmentsCallback(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent,Boolean useUids)818 static void GetAlignmentsCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent, Boolean useUids)
819 
820 {
821   Uint1          align_type;
822   BioseqPtr      bsp;
823   BioseqSetPtr   bssp;
824   ObjectIdPtr    oip;
825   SeqAnnotPtr    sap;
826   UserFieldPtr   ufp;
827   UserObjectPtr  uop;
828   ValNodePtr     vnp;
829 
830   if (sep == NULL || sep->data.ptrvalue == NULL) return;
831   sap = NULL;
832   if (IS_Bioseq (sep)) {
833     bsp = (BioseqPtr) sep->data.ptrvalue;
834     sap = bsp->annot;
835   } else if (IS_Bioseq_set (sep)) {
836     bssp = (BioseqSetPtr) sep->data.ptrvalue;
837     sap = bssp->annot;
838   } else return;
839   while (sap != NULL) {
840     if (sap->type == 2) {
841       align_type = 0;
842       for (vnp = sap->desc; vnp != NULL; vnp = vnp->next) {
843         if (vnp->choice == Annot_descr_user) {
844           uop = (UserObjectPtr) vnp->data.ptrvalue;
845           if (uop != NULL) {
846             oip = uop->type;
847             if (oip != NULL && StringICmp (oip->str, "Blast Type") == 0) {
848               ufp = uop->data;
849               if (ufp != NULL && ufp->choice == 2) {
850                 align_type = ufp->data.intvalue;
851               }
852             }
853           }
854         }
855       }
856       GetSeqIdsForOneSeqAnnot (sap, (ValNodePtr PNTR) mydata, align_type, useUids);
857     }
858     sap = sap->next;
859   }
860 }
861 
GetUidsAlignmentsCallback(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)862 static void GetUidsAlignmentsCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
863 
864 {
865   GetAlignmentsCallback (sep, mydata, index, indent, TRUE);
866 }
867 
GetStrIdsAlignmentsCallback(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)868 static void GetStrIdsAlignmentsCallback (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
869 
870 {
871   GetAlignmentsCallback (sep, mydata, index, indent, FALSE);
872 }
873 
SortByVnpDataIntvalue(VoidPtr ptr1,VoidPtr ptr2)874 extern int LIBCALLBACK SortByVnpDataIntvalue (VoidPtr ptr1, VoidPtr ptr2)
875 
876 {
877   ValNodePtr   vnp1;
878   ValNodePtr   vnp2;
879 
880   if (ptr1 != NULL && ptr2 != NULL) {
881     vnp1 = *((ValNodePtr PNTR) ptr1);
882     vnp2 = *((ValNodePtr PNTR) ptr2);
883     if (vnp1 != NULL && vnp2 != NULL) {
884       if (vnp1->data.intvalue > vnp2->data.intvalue) {
885         return 1;
886       } else if (vnp1->data.intvalue < vnp2->data.intvalue) {
887         return -1;
888       } else {
889         return 0;
890       }
891     } else {
892       return 0;
893     }
894   } else {
895     return 0;
896   }
897 }
898 
SortByName(VoidPtr ptr1,VoidPtr ptr2)899 static int LIBCALLBACK SortByName (VoidPtr ptr1, VoidPtr ptr2)
900 
901 {
902   CharPtr     str1;
903   CharPtr     str2;
904   ValNodePtr  vnp1;
905   ValNodePtr  vnp2;
906 
907   if (ptr1 != NULL && ptr2 != NULL) {
908     vnp1 = *((ValNodePtr PNTR) ptr1);
909     vnp2 = *((ValNodePtr PNTR) ptr2);
910     if (vnp1 != NULL && vnp2 != NULL) {
911       str1 = (CharPtr) vnp1->data.ptrvalue;
912       str2 = (CharPtr) vnp2->data.ptrvalue;
913       if (str1 != NULL && str2 != NULL) {
914         return StringICmp (str1, str2);
915       } else {
916         return 0;
917       }
918     } else {
919       return 0;
920     }
921   } else {
922     return 0;
923   }
924 }
925 
GetUidsForSeqEntryAligns(SeqEntryPtr sep)926 extern ValNodePtr LIBCALL GetUidsForSeqEntryAligns (SeqEntryPtr sep)
927 
928 {
929   Uint1            choice;
930   ValNodePtr       head;
931   ValNodePtr       next;
932   ValNodePtr PNTR  prev;
933   Int4             uid;
934   ValNodePtr       vnp;
935 
936   head = NULL;
937   if (sep == NULL) return NULL;
938   SeqEntryExplore (sep, (Pointer) (&head), GetUidsAlignmentsCallback);
939   if (head == NULL) return NULL;
940   head = SortValNode (head, SortByVnpDataIntvalue);
941   uid = 0;
942   choice = 0;
943   prev = (ValNodePtr PNTR) &head;
944   vnp = head;
945   while (vnp != NULL) {
946     next = vnp->next;
947     if (vnp->data.intvalue == uid && vnp->choice == choice) {
948       *(prev) = vnp->next;
949       vnp->next = NULL;
950       ValNodeFree (vnp);
951     } else {
952       uid = vnp->data.intvalue;
953       choice = vnp->choice;
954       prev = (ValNodePtr PNTR) &(vnp->next);
955     }
956     vnp = next;
957   }
958   return head;
959 }
960 
GetIdStringsForSeqEntryAligns(SeqEntryPtr sep)961 extern ValNodePtr LIBCALL GetIdStringsForSeqEntryAligns (SeqEntryPtr sep)
962 
963 {
964   Uint1            choice;
965   ValNodePtr       head;
966   CharPtr          last;
967   ValNodePtr       next;
968   ValNodePtr PNTR  prev;
969   ValNodePtr       vnp;
970 
971   head = NULL;
972   if (sep == NULL) return NULL;
973   SeqEntryExplore (sep, (Pointer) (&head), GetStrIdsAlignmentsCallback);
974   if (head == NULL) return NULL;
975   head = SortValNode (head, SortByName);
976   last = NULL;
977   choice = 0;
978   prev = (ValNodePtr PNTR) &head;
979   vnp = head;
980   while (vnp != NULL) {
981     next = vnp->next;
982     if (StringICmp ((CharPtr) vnp->data.ptrvalue, last) == 0 && vnp->choice == choice) {
983       *(prev) = vnp->next;
984       vnp->next = NULL;
985       ValNodeFree (vnp);
986     } else {
987       last = (CharPtr) vnp->data.ptrvalue;
988       choice = vnp->choice;
989       prev = (ValNodePtr PNTR) &(vnp->next);
990     }
991     vnp = next;
992   }
993   return head;
994 }
995 
ResizeViewForm(WindoW w)996 static void ResizeViewForm (WindoW w)
997 
998 {
999   BioseqViewFormPtr  bfp;
1000   Int2               bottom;
1001   BioseqPagePtr      bpp;
1002   RecT               c;
1003   Int2               diff = 0;
1004   Int2               gap = 0;
1005   Int2               height;
1006   RecT               r;
1007   RecT               s;
1008   RecT               t;
1009   Int2               width;
1010 
1011   bfp = (BioseqViewFormPtr) GetObjectExtra (w);
1012   if (bfp == NULL) return;
1013   WatchCursor ();
1014   ObjectRect (w, &r);
1015   width = r.right - r.left;
1016   height = r.bottom - r.top;
1017   bottom = height - 10;
1018   SafeHide (bfp->controls);
1019   SafeHide (bfp->retrieveAlignments);
1020 
1021   if (bfp->controls != NULL) {
1022     GetPosition (bfp->controls, &c);
1023     LoadRect (&t, c.left, c.top, c.right, c.bottom);
1024     diff = t.bottom - t.top;
1025     gap = 10;
1026     t.bottom = height - 10;
1027     t.top = t.bottom - diff;
1028     t.right = width - 10;
1029     SetPosition (bfp->controls, &t);
1030     AdjustPrnt (bfp->controls, &t, FALSE);
1031     bottom = t.top - gap;
1032   } else if (bfp->retrieveAlignments != NULL) {
1033     GetPosition (bfp->retrieveAlignments, &c);
1034     LoadRect (&t, c.left, c.top, c.right, c.bottom);
1035     diff = t.bottom - t.top;
1036     gap = 10;
1037     t.bottom = height - 10;
1038     t.top = t.bottom - diff;
1039     SetPosition (bfp->retrieveAlignments, &t);
1040     AdjustPrnt (bfp->retrieveAlignments, &t, FALSE);
1041     if (bfp->hasaligns) {
1042       bottom = t.top - gap;
1043     }
1044   }
1045 
1046   if (bfp->bvd.vwr != NULL) {
1047     GetPosition (bfp->bvd.vwr, &s);
1048     s.right = width - 10;
1049     s.bottom = bottom;
1050     SetPosition (bfp->bvd.vwr, &s);
1051     AdjustPrnt (bfp->bvd.vwr, &s, FALSE);
1052   }
1053   if (bfp->bvd.doc != NULL) {
1054     GetPosition (bfp->bvd.doc, &s);
1055     s.right = width - 10;
1056     s.bottom = bottom;
1057     SetPosition (bfp->bvd.doc, &s);
1058     AdjustPrnt (bfp->bvd.doc, &s, FALSE);
1059   }
1060   if (bfp->bvd.text != NULL) {
1061     GetPosition (bfp->bvd.text, &s);
1062     s.right = width - 10;
1063     s.bottom = bottom;
1064     SetPosition (bfp->bvd.text, &s);
1065     AdjustPrnt (bfp->bvd.text, &s, FALSE);
1066   }
1067   if (bfp->bvd.pnl != NULL) {
1068     GetPosition (bfp->bvd.pnl, &s);
1069     s.right = width - 10;
1070     s.bottom = bottom;
1071     SetPosition (bfp->bvd.pnl, &s);
1072     AdjustPrnt (bfp->bvd.pnl, &s, FALSE);
1073   }
1074   if (bfp->bvd.seqView != NULL) {
1075     GetPosition (bfp->bvd.seqView, &s);
1076     s.right = width - 10;
1077     s.bottom = bottom;
1078     SetPosition (bfp->bvd.seqView, &s);
1079     AdjustPrnt (bfp->bvd.seqView, &s, FALSE);
1080   }
1081   if (bfp->bvd.clickMe != NULL) {
1082     GetPosition (bfp->bvd.clickMe, &s);
1083     s.right = width - 10;
1084     SetPosition (bfp->bvd.clickMe, &s);
1085     AdjustPrnt (bfp->bvd.clickMe, &s, FALSE);
1086   }
1087   /*
1088   if (bfp->bvd.udv != NULL) {
1089     GetPosition (bfp->bvd.udv, &s);
1090     s.right = width - 10;
1091     s.bottom = bottom;
1092     SetPosition (bfp->bvd.udv, &s);
1093     AdjustPrnt (bfp->bvd.udv, &s, FALSE);
1094   }
1095   if (bfp->bvd.ddv != NULL) {
1096     GetPosition (bfp->bvd.ddv, &s);
1097     s.right = width - 10;
1098     s.bottom = bottom;
1099     SetPosition (bfp->bvd.ddv, &s);
1100     AdjustPrnt (bfp->bvd.ddv, &s, FALSE);
1101   }
1102   */
1103   /*
1104   if (bfp->bvd.vwr != NULL) {
1105     if (Visible (bfp->bvd.vwr) && AllParentsVisible (bfp->bvd.vwr)) {
1106       ViewerWasResized (bfp->bvd.vwr);
1107     }
1108   }
1109   if (bfp->bvd.doc != NULL) {
1110     if (Visible (bfp->bvd.doc) && AllParentsVisible (bfp->bvd.doc)) {
1111       UpdateDocument (bfp->bvd.doc, 0, 0);
1112     }
1113   }
1114   */
1115   bpp = bfp->currentBioseqPage;
1116   if (bpp != NULL) {
1117     if (bpp->resize != NULL) {
1118       bpp->resize (&(bfp->bvd));
1119     }
1120   }
1121   if (bfp->controls != NULL) {
1122     SafeShow (bfp->controls);
1123   } else if (bfp->retrieveAlignments != NULL && bfp->hasaligns) {
1124     SafeShow (bfp->retrieveAlignments);
1125   }
1126   ArrowCursor ();
1127   Update ();
1128 }
1129 
PopTargetAlistProc(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)1130 static void PopTargetAlistProc (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
1131 
1132 {
1133   BioseqViewFormPtr  bfp;
1134   BioseqPtr          bsp;
1135   Char               ch;
1136   CharPtr            ptr;
1137   SeqIdPtr           sip;
1138   Char               str [128];
1139   CharPtr            tmp;
1140   static BioseqViewFormPtr already_complained_about_sequences = NULL;
1141 
1142   bfp = (BioseqViewFormPtr) mydata;
1143   if (bfp != NULL && sep != NULL && sep->choice == 1 && sep->data.ptrvalue != NULL) {
1144     if (bfp->workingCount > MAX_VIEWABLE_TARGET_SEQUENCES) {
1145       if (already_complained_about_sequences != bfp) {
1146           Message (MSG_ERROR, "Too many sequences to list in navigation controls!");
1147           already_complained_about_sequences = bfp;
1148       }
1149       return; /* don't want list to get too long */
1150     }
1151     bsp = (BioseqPtr) sep->data.ptrvalue;
1152     sip = SeqIdFindWorst (bsp->id);
1153     SeqIdWrite (sip, str, PRINTID_REPORT, sizeof (str));
1154     ptr = StringChr (str, '|');
1155     if (ptr == NULL) {
1156       ptr = str;
1157     } else {
1158       ptr++;
1159     }
1160     tmp = StringSave (ptr);
1161     bfp->workingAlist [bfp->workingCount].name = tmp;
1162     if (tmp != NULL) {
1163       ch = *tmp;
1164       while (ch != '\0') {
1165         if (ch == '/') {
1166           *tmp = '-';
1167         }
1168         tmp++;
1169         ch = *tmp;
1170       }
1171     }
1172     (bfp->workingCount)++;
1173     if (bsp == bfp->bvd.bsp) {
1174       bfp->targetScratchSpace = index + 1;
1175     }
1176   }
1177 }
1178 
MakeTargetAlist(BioseqViewFormPtr bfp,SeqEntryPtr sep)1179 static EnumFieldAssocPtr MakeTargetAlist (BioseqViewFormPtr bfp, SeqEntryPtr sep)
1180 
1181 {
1182   EnumFieldAssocPtr  alist;
1183   Int4               num;
1184 
1185   if (bfp == NULL || sep == NULL) return NULL;
1186   bfp->workingAlist = NULL;
1187   bfp->workingCount = 0;
1188   num = SequinEntryCount (sep);
1189   bfp->workingAlist = MemNew (sizeof (EnumFieldAssoc) * (num + 3));
1190   if (bfp->workingAlist == NULL) return NULL;
1191   bfp->workingAlist [bfp->workingCount].name = StringSave ("ALL SEQUENCES");
1192   (bfp->workingCount)++;
1193   bfp->workingTargets = SequinEntryExplore (sep, (Pointer) bfp, PopTargetAlistProc);
1194   alist = bfp->workingAlist;
1195   bfp->workingAlist = NULL;
1196   bfp->workingCount = 0;
1197   return alist;
1198 }
1199 
PopulateTarget(BioseqViewFormPtr bfp)1200 static Int4 PopulateTarget (BioseqViewFormPtr bfp)
1201 
1202 {
1203   EnumFieldAssocPtr  ap;
1204   Int4               count;
1205   Uint2              entityID;
1206   SeqEntryPtr        sep;
1207   Int4               val;
1208 
1209   val = 0;
1210   if (bfp != NULL && bfp->bvd.bsp != NULL) {
1211     bfp->targetAlist = FreeEnumFieldAlist (bfp->targetAlist);
1212     entityID = ObjMgrGetEntityIDForPointer (bfp->bvd.bsp);
1213     sep = GetTopSeqEntryForEntityID (entityID);
1214     if (sep != NULL) {
1215       bfp->targetScratchSpace = 0;
1216       bfp->workingTargets = 0;
1217       bfp->targetAlist = MakeTargetAlist (bfp, sep);
1218       for (ap = bfp->targetAlist, count = 0; ap != NULL && ap->name != NULL; ap++, count++) {
1219         if (bfp->usePopupForTarget) {
1220           if (count < 32) {
1221             PopupItem (bfp->targetControl, ap->name);
1222           }
1223         } else {
1224           if (count < MAX_VIEWABLE_TARGET_SEQUENCES) {
1225             ListItem (bfp->targetControl, ap->name);
1226           }
1227         }
1228       }
1229       bfp->numTargets = bfp->workingTargets;
1230       val = bfp->targetScratchSpace;
1231     }
1232   }
1233   return val;
1234 }
1235 
GetUidFromBsp(BioseqPtr bsp)1236 static BIG_ID GetUidFromBsp (BioseqPtr bsp)
1237 
1238 {
1239   SeqIdPtr  sip;
1240 
1241   if (bsp == NULL) return 0;
1242   sip = bsp->id;
1243   while (sip != NULL) {
1244     if (sip->choice == SEQID_GI) {
1245       return (BIG_ID) sip->data.intvalue;
1246     }
1247     sip = sip->next;
1248   }
1249   return 0;
1250 }
1251 
1252 /*
1253 static void CheckForCookedBioseqs (SeqEntryPtr sep, Pointer mydata, Int4 index, Int2 indent)
1254 
1255 {
1256   BoolPtr    bp;
1257   BioseqPtr  bsp;
1258 
1259   if (sep == NULL) return;
1260   if (! IS_Bioseq (sep)) return;
1261   bp = (BoolPtr) mydata;
1262   if (bp == NULL) return;
1263   bsp = (BioseqPtr) sep->data.ptrvalue;
1264   if (bsp == NULL) return;
1265   if (bsp->repr != Seq_repr_raw && bsp->repr != Seq_repr_seg) {
1266     *bp = FALSE;
1267   }
1268 }
1269 */
1270 
BioseqPtrToBioseqForm(ForM f,Pointer data)1271 static void BioseqPtrToBioseqForm (ForM f, Pointer data)
1272 
1273 {
1274   EnumFieldAssocPtr  alist;
1275   Boolean            allRawOrSeg = TRUE;
1276   EnumFieldAssocPtr  ap1, ap2;
1277   BioseqViewFormPtr  bfp;
1278   BioseqPagePtr      bpp;
1279   BioseqPtr          bsp;
1280   Int4               count;
1281   Uint2              entityID;
1282   SeqEntryPtr        sep;
1283   Int2               val;
1284 
1285   bfp = (BioseqViewFormPtr) GetObjectExtra (f);
1286   bsp = (BioseqPtr) data;
1287   if (bfp != NULL && bsp != NULL) {
1288     /*
1289     if (bfp->bvd.bsp != bsp) {
1290       BioseqLock (bsp);
1291       BioseqUnlock (bfp->bvd.bsp);
1292     }
1293     */
1294     bfp->bvd.bsp = bsp;
1295     bfp->docuid = GetUidFromBsp (bsp);
1296     if (bfp->docuid > 0) {
1297       SafeShow (bfp->pubseq);
1298     } else {
1299       SafeHide (bfp->pubseq);
1300     }
1301     if (ISA_na (bsp->mol)) {
1302       bfp->doctype = TYP_NT;
1303     } else if (ISA_aa (bsp->mol)) {
1304       bfp->doctype = TYP_AA;
1305     }
1306     entityID = ObjMgrGetEntityIDForPointer (bsp);
1307     sep = GetTopSeqEntryForEntityID (entityID);
1308     count = SequinEntryCount (sep);
1309     if (bfp->numTargets == count && sep != NULL) {
1310       alist = MakeTargetAlist (bfp, sep);
1311       if (alist != NULL && bfp->targetAlist) {
1312         for (ap1 = alist, ap2 = bfp->targetAlist;
1313              ap1->name != NULL && ap2->name != NULL;
1314              ap1++, ap2++) {
1315           if (StringICmp (ap1->name, ap2->name) != 0) {
1316             count = bfp->numTargets + 1; /* seqIDs have changed, so force repopulation */
1317           }
1318         }
1319       }
1320       alist = FreeEnumFieldAlist (alist);
1321     }
1322     if (bfp->numTargets != count) {
1323       val = GetValue (bfp->targetControl);
1324       Hide (bfp->targetControl);
1325       Update ();
1326       Reset (bfp->targetControl);
1327       PopulateTarget (bfp);
1328       SetValue (bfp->targetControl, val);
1329       Show (bfp->targetControl);
1330     }
1331     Update ();
1332     bpp = bfp->currentBioseqPage;
1333     if (bpp != NULL) {
1334       if (bpp->populate != NULL) {
1335         /* oldErrSev = ErrSetMessageLevel (SEV_FATAL); */
1336         if (bfp->bvd.hasTargetControl) { /* just sequin, for now */
1337           sep = GetTopSeqEntryForEntityID (entityID);
1338           /*
1339           SeqEntryExplore (sep, (Pointer) (&allRawOrSeg), CheckForCookedBioseqs);
1340           */
1341           if (allRawOrSeg) {
1342             if (SeqMgrFeaturesAreIndexed (entityID) == 0) {
1343               SeqMgrIndexFeatures (entityID, NULL);
1344             }
1345           }
1346         }
1347         BioseqLock (bsp);
1348         bpp->populate (&(bfp->bvd));
1349         BioseqUnlock (bsp);
1350         Update ();
1351         /* ErrSetMessageLevel (oldErrSev); */
1352       }
1353       if (bfp->retrieveAlignments != NULL && bfp->updateCounts != NULL) {
1354         entityID = ObjMgrGetEntityIDForPointer (bsp);
1355         sep = GetTopSeqEntryForEntityID (entityID);
1356         bfp->hasaligns = bfp->updateCounts (bfp->retrieveAlignments, sep);
1357         if (Visible (bfp->retrieveAlignments)) {
1358           if (! bfp->hasaligns) {
1359             ResizeViewForm ((WindoW) f);
1360           }
1361         } else {
1362           if (bfp->hasaligns) {
1363             ResizeViewForm ((WindoW) f);
1364           }
1365         }
1366       }
1367       if (bpp->show != NULL) {
1368         bpp->show (&(bfp->bvd), TRUE);
1369       }
1370     }
1371   }
1372 }
1373 
CopyBioseqViewFormToClipboard(Pointer formDataPtr)1374 static void LIBCALL CopyBioseqViewFormToClipboard (Pointer formDataPtr)
1375 
1376 {
1377   BioseqViewFormPtr  bfp;
1378   BioseqPagePtr      bpp;
1379 
1380   bfp = (BioseqViewFormPtr) formDataPtr;
1381   if (bfp == NULL || bfp->bvd.bsp == NULL) return;
1382   bpp = bfp->currentBioseqPage;
1383   if (bpp == NULL) return;
1384   if (bpp->toClipboard != NULL) {
1385     bpp->toClipboard (&(bfp->bvd));
1386   }
1387 }
1388 
ExportBioseqViewFormToFile(Pointer formDataPtr,CharPtr filename)1389 static void LIBCALL ExportBioseqViewFormToFile (Pointer formDataPtr, CharPtr filename)
1390 
1391 {
1392   BioseqViewFormPtr  bfp;
1393   BioseqPagePtr      bpp;
1394   Char               dfault [32];
1395 
1396   bfp = (BioseqViewFormPtr) formDataPtr;
1397   if (bfp == NULL || bfp->bvd.bsp == NULL) return;
1398   bpp = bfp->currentBioseqPage;
1399   if (bpp == NULL) return;
1400   if (bpp->exprt != NULL) {
1401     GetTitle (bfp->form, dfault, sizeof (dfault));
1402     bpp->exprt (&(bfp->bvd), NULL, dfault);
1403   }
1404 }
1405 
ShortDefFastaFileFunc(BioseqPtr bsp,Int2 key,CharPtr buf,Uint4 buflen,Pointer data)1406 static Boolean ShortDefFastaFileFunc (BioseqPtr bsp, Int2 key, CharPtr buf, Uint4 buflen, Pointer data)
1407 
1408 {
1409     Int2  code;
1410     CharPtr  buffer;
1411     Uint2  entityID;
1412     FILE * fp;
1413     size_t  len;
1414     Char  org [200];
1415     /* CharPtr  ptr; */
1416     SeqEntryPtr  sep;
1417     Char  tmp [16];
1418 
1419     fp = (FILE *)data;
1420 
1421     switch (key)
1422     {
1423         case FASTA_ID:
1424             fprintf(fp, ">%s ", buf);
1425             break;
1426         case FASTA_DEFLINE:
1427             entityID = ObjMgrGetEntityIDForPointer (bsp);
1428             sep = GetBestTopParentForData (entityID, bsp);
1429             code = SeqEntryToGeneticCode (sep, NULL, org, sizeof (org) - 21);
1430             if (! StringHasNoText (org)) {
1431                 StringCat (org, "]");
1432                 if (code > 0) {
1433                      sprintf (tmp, " [code=%d]", (int) code);
1434                      StringCat (org, tmp);
1435                 }
1436             }
1437             len = StringLen (buf) + StringLen (org) + 20;
1438             buffer = MemNew (len);
1439             /*
1440             ptr = StringChr (buf, ' ');
1441             if (ptr != NULL) {
1442               *ptr = '\0';
1443               ptr++;
1444             }
1445             StringCpy (buffer, buf);
1446             */
1447             if (org [0] != '\0') {
1448               StringCat (buffer, "[org=");
1449               StringCat (buffer, org);
1450               if (! StringHasNoText (buf)) {
1451                 StringCat (buffer, " ");
1452               }
1453             }
1454             if (! StringHasNoText (buf)) {
1455               StringCat (buffer, buf);
1456             }
1457             if (StringLen (buffer) > 253) {
1458               buffer [251] = '.';
1459               buffer [252] = '.';
1460               buffer [253] = '.';
1461               buffer [254] = '\0';
1462             }
1463             fprintf(fp, "%s\n", buffer);
1464             MemFree (buffer);
1465             break;
1466         case FASTA_SEQLINE:
1467             fprintf(fp, "%s\n", buf);
1468             break;
1469         case FASTA_EOS:   /* end of sequence */
1470             break;
1471         default:
1472             break;
1473     }
1474     return TRUE;
1475 }
1476 
SeqnSeqEntrysToFasta(SeqEntryPtr sep,FILE * fp,Boolean is_na,Uint1 group_segs)1477 extern Boolean SeqnSeqEntrysToFasta (SeqEntryPtr sep, FILE *fp, Boolean is_na, Uint1 group_segs)
1478 
1479 {
1480     FastaDat tfa;
1481     MyFsa mfa;
1482     Char buf[255];
1483 
1484     if ((sep == NULL) || (fp == NULL))
1485         return FALSE;
1486 
1487     MemSet ((Pointer) (&mfa), 0, sizeof (MyFsa));
1488     mfa.buf = buf;
1489     mfa.buflen = 254;
1490     mfa.seqlen = 70;
1491     mfa.mydata = (Pointer)fp;
1492     mfa.myfunc = ShortDefFastaFileFunc;
1493     mfa.bad_asn1 = FALSE;
1494     mfa.order = 0;
1495     mfa.accession = NULL;
1496     mfa.organism = NULL;
1497     mfa.do_virtual = FALSE;
1498     mfa.tech = 0;
1499     mfa.no_sequence = FALSE;
1500     mfa.formatdb    = FALSE;
1501 
1502     tfa.mfp = &mfa;
1503     tfa.is_na = is_na;
1504 
1505     if (is_na)
1506         mfa.code = Seq_code_iupacna;
1507     else
1508         mfa.code = Seq_code_ncbieaa;
1509 
1510     if (group_segs == 3)  /* do 2 things */
1511     {
1512         mfa.do_virtual = TRUE;
1513         group_segs = 1;
1514     }
1515     tfa.group_segs = group_segs;
1516     tfa.last_indent = -1;
1517     tfa.parts = -1;
1518     tfa.seg = -1;
1519     tfa.got_one = FALSE;
1520     SeqEntryExplore(sep, (Pointer)&tfa, SeqEntryFasta);
1521     return tfa.got_one;
1522 }
1523 
BioseqViewCanSaveFasta(ForM f,Boolean nucs,Boolean prots,Boolean onlyTarget)1524 extern Boolean BioseqViewCanSaveFasta (ForM f, Boolean nucs, Boolean prots, Boolean onlyTarget)
1525 
1526 {
1527   BioseqViewFormPtr  bfp;
1528   BioseqPtr          bsp;
1529   BioseqViewPtr      bvp;
1530   Uint2              entityID;
1531   SeqEntryPtr        sep;
1532 
1533   bfp = (BioseqViewFormPtr) GetObjectExtra (f);
1534   if (bfp != NULL) {
1535     bvp = (&(bfp->bvd));
1536     if (bvp == NULL) return FALSE;
1537     bsp = bvp->bsp;
1538     if (bsp == NULL) return FALSE;
1539     sep = SeqMgrGetSeqEntryForData (bsp);
1540     if (! onlyTarget) {
1541       entityID = ObjMgrGetEntityIDForChoice (sep);
1542       sep = GetTopSeqEntryForEntityID (entityID);
1543     }
1544     if (sep == NULL) return FALSE;
1545     if (nucs && SeqEntryHasNucs (sep)) return TRUE;
1546     if (prots && SeqEntryHasProts (sep)) return TRUE;
1547   }
1548   return FALSE;
1549 }
1550 
ExportBioseqViewFasta(ForM f,CharPtr filename,Boolean nucs,Boolean prots,Boolean onlyTarget)1551 extern Boolean ExportBioseqViewFasta (ForM f, CharPtr filename, Boolean nucs, Boolean prots, Boolean onlyTarget)
1552 
1553 {
1554   BioseqViewFormPtr  bfp;
1555   BioseqPtr          bsp;
1556   BioseqViewPtr      bvp;
1557   Uint2              entityID;
1558   FILE               *fp;
1559   Uint1              group_segs;
1560   Char               path [PATH_MAX];
1561   SeqEntryPtr        sep;
1562 
1563   path [0] = '\0';
1564   StringNCpy_0 (path, filename, sizeof (path));
1565   bfp = (BioseqViewFormPtr) GetObjectExtra (f);
1566   if (bfp != NULL) {
1567     bvp = (&(bfp->bvd));
1568     if (bvp == NULL) return FALSE;
1569     bsp = bvp->bsp;
1570     if (bsp == NULL) return FALSE;
1571     sep = SeqMgrGetSeqEntryForData (bsp);
1572     if (! onlyTarget) {
1573       entityID = ObjMgrGetEntityIDForChoice (sep);
1574       sep = GetTopSeqEntryForEntityID (entityID);
1575     }
1576     if (path [0] != '\0' || GetOutputFileName (path, sizeof (path), NULL)) {
1577 #ifdef WIN_MAC
1578       fp = FileOpen (path, "r");
1579       if (fp != NULL) {
1580         FileClose (fp);
1581       } else {
1582         FileCreate (path, "TEXT", "ttxt");
1583       }
1584 #endif
1585       fp = FileOpen (path, "w");
1586       if (fp != NULL) {
1587         WatchCursor ();
1588         Update ();
1589         group_segs = 0;
1590         if (bsp->repr == Seq_repr_seg) {
1591           group_segs = 2;
1592         }
1593         if (nucs) {
1594           SeqnSeqEntrysToFasta (sep, fp, TRUE, group_segs);
1595         }
1596         if (prots) {
1597           SeqnSeqEntrysToFasta (sep, fp, FALSE, 0);
1598         }
1599         FileClose (fp);
1600         ArrowCursor ();
1601         Update ();
1602         return TRUE;
1603       }
1604     }
1605   }
1606   return FALSE;
1607 }
1608 
PrintBioseqViewForm(Pointer formDataPtr)1609 static void LIBCALL PrintBioseqViewForm (Pointer formDataPtr)
1610 
1611 {
1612   BioseqViewFormPtr  bfp;
1613   BioseqPagePtr      bpp;
1614 
1615   bfp = (BioseqViewFormPtr) formDataPtr;
1616   if (bfp == NULL || bfp->bvd.bsp == NULL) return;
1617   bpp = bfp->currentBioseqPage;
1618   if (bpp == NULL) return;
1619   if (bpp->print != NULL) {
1620     bpp->print (&(bfp->bvd));
1621   }
1622 }
1623 
NewSaveBioseqViewFormGifItemTable(Pointer formDataPtr,CharPtr filename)1624 extern void LIBCALL NewSaveBioseqViewFormGifItemTable (Pointer formDataPtr, CharPtr filename)
1625 
1626 {
1627   BioseqViewFormPtr  bfp;
1628   BioseqPagePtr      bpp;
1629 
1630   bfp = (BioseqViewFormPtr) formDataPtr;
1631   if (bfp == NULL || bfp->bvd.bsp == NULL) return;
1632   bpp = bfp->currentBioseqPage;
1633   if (bpp == NULL) return;
1634   if (bpp->togif != NULL) {
1635     bpp->togif (&(bfp->bvd), filename, NULL);
1636   }
1637 }
1638 
SetBioseqImportExportItems(BioseqViewFormPtr bfp)1639 static void SetBioseqImportExportItems (BioseqViewFormPtr bfp)
1640 
1641 {
1642   BioseqPagePtr  bpp;
1643   IteM           exportItm;
1644   Char           str [64];
1645   CharPtr        tmp;
1646 
1647   if (bfp == NULL || bfp->bvd.bsp == NULL) return;
1648   bpp = bfp->currentBioseqPage;
1649   if (bpp == NULL) return;
1650   exportItm = FindFormMenuItem ((BaseFormPtr) bfp, VIB_MSG_EXPORT);
1651   if (bpp->exprt != NULL) {
1652     tmp = StringMove (str, "Export ");
1653     StringNCpy_0 (tmp, bpp->label, sizeof (str) - 12);
1654     StringCat (tmp, "...");
1655     SafeSetTitle (exportItm, str);
1656     SafeEnable (exportItm);
1657   } else {
1658     SafeSetTitle (exportItm, "Export...");
1659     SafeDisable (exportItm);
1660   }
1661 }
1662 
SetCurrentPagePointers(BioseqViewFormPtr bfp)1663 static void SetCurrentPagePointers (BioseqViewFormPtr bfp)
1664 
1665 {
1666   BioseqPagePtr  bpp;
1667   Int2           page;
1668 
1669   if (bfp == NULL || bfp->bvd.bsp == NULL) return;
1670   bpp = NULL;
1671   page = 0;
1672   if (ISA_na (bfp->bvd.bsp->mol)) {
1673     bpp = bfp->bioseqNucPageList;
1674     page = bfp->currentNucPage;
1675   } else if (ISA_aa (bfp->bvd.bsp->mol)) {
1676     bpp = bfp->bioseqProtPageList;
1677     page = bfp->currentProtPage;
1678   }
1679   while (bpp != NULL && page > 0) {
1680     bpp = bpp->next;
1681     page--;
1682   }
1683   bfp->currentBioseqPage = bpp;
1684 }
1685 
AdjustDynamicGraphicViewer(BioseqViewPtr bvp)1686 static void AdjustDynamicGraphicViewer (BioseqViewPtr bvp)
1687 
1688 {
1689   if (bvp == NULL) return;
1690   if (Visible (bvp->vwr)) {
1691     if (PictureGrew (bvp->vwr)) {
1692       PictureHasEnlarged (bvp->vwr);
1693     }
1694   }
1695 }
1696 
1697 
HideBioseqView(WindoW w)1698 NLM_EXTERN void HideBioseqView (WindoW w)
1699 {
1700   BioseqViewFormPtr bfp;
1701   BioseqPagePtr     bpp;
1702 
1703   bfp = (BioseqViewFormPtr) GetObjectExtra (w);
1704   if (bfp != NULL) {
1705     WatchCursor ();
1706     bfp->bvd.scaleNotCalculated = TRUE;
1707     bfp->bvd.moveToOldPos = FALSE;
1708     bpp = bfp->currentBioseqPage;
1709     if (bpp != NULL && bpp->show != NULL) {
1710       bpp->show (&(bfp->bvd), FALSE);
1711     }
1712     Update ();
1713   }
1714 }
1715 
1716 
ChangeBioseqViewTabs(VoidPtr data,Int2 newval,Int2 oldval)1717 static void ChangeBioseqViewTabs (VoidPtr data, Int2 newval, Int2 oldval)
1718 
1719 {
1720   BioseqViewFormPtr  bfp;
1721   BioseqPagePtr      bpp;
1722   BioseqPtr          bsp;
1723 
1724   bfp = (BioseqViewFormPtr) data;
1725   if (bfp != NULL && bfp->bvd.bsp != NULL) {
1726     WatchCursor ();
1727     bsp = bfp->bvd.bsp;
1728     bfp->bvd.scaleNotCalculated = TRUE;
1729     bfp->bvd.moveToOldPos = FALSE;
1730     bpp = bfp->currentBioseqPage;
1731     if (bpp != NULL && bpp->show != NULL) {
1732       bpp->show (&(bfp->bvd), FALSE);
1733     }
1734     Update ();
1735     bfp->bvd.old_rect_shown = FALSE;
1736     if (ISA_na (bsp->mol)) {
1737       bfp->currentNucPage = newval;
1738     } else if (ISA_aa (bsp->mol)) {
1739       bfp->currentProtPage = newval;
1740     }
1741     SetCurrentPagePointers (bfp);
1742     PointerToForm (bfp->form, (Pointer) bfp->bvd.bsp);
1743     SetBioseqImportExportItems (bfp);
1744     ArrowCursor ();
1745     Update ();
1746     AdjustDynamicGraphicViewer (&(bfp->bvd));
1747   }
1748 }
1749 
ChangeBioseqSequenceStyle(PopuP p)1750 static void ChangeBioseqSequenceStyle (PopuP p)
1751 
1752 {
1753   BioseqViewFormPtr  bfp;
1754   BioseqPagePtr      bpp;
1755 
1756   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
1757   if (bfp != NULL && bfp->bvd.bsp != NULL) {
1758     WatchCursor ();
1759     bfp->bvd.moveToOldPos = FALSE;
1760     bpp = bfp->currentBioseqPage;
1761     if (bpp != NULL && bpp->show != NULL) {
1762       bpp->show (&(bfp->bvd), FALSE);
1763     }
1764     Update ();
1765     PointerToForm (bfp->form, (Pointer) bfp->bvd.bsp);
1766     SetBioseqImportExportItems (bfp);
1767     ArrowCursor ();
1768     Update ();
1769     AdjustDynamicGraphicViewer (&(bfp->bvd));
1770   }
1771 }
1772 
ChangeBioseqSequenceRIF(PopuP p)1773 static void ChangeBioseqSequenceRIF (PopuP p)
1774 
1775 {
1776   BioseqViewFormPtr  bfp;
1777   BioseqPagePtr      bpp;
1778 
1779   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
1780   if (bfp != NULL && bfp->bvd.bsp != NULL) {
1781     WatchCursor ();
1782     bfp->bvd.moveToOldPos = FALSE;
1783     bpp = bfp->currentBioseqPage;
1784     if (bpp != NULL && bpp->show != NULL) {
1785       bpp->show (&(bfp->bvd), FALSE);
1786     }
1787     Update ();
1788     PointerToForm (bfp->form, (Pointer) bfp->bvd.bsp);
1789     SetBioseqImportExportItems (bfp);
1790     ArrowCursor ();
1791     Update ();
1792     AdjustDynamicGraphicViewer (&(bfp->bvd));
1793   }
1794 }
1795 
ChangeFlatFileExtras(PopuP p)1796 static void ChangeFlatFileExtras (PopuP p)
1797 
1798 {
1799   BioseqViewFormPtr  bfp;
1800   BioseqPagePtr      bpp;
1801 
1802   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
1803   if (bfp != NULL && bfp->bvd.bsp != NULL) {
1804     WatchCursor ();
1805     bfp->bvd.moveToOldPos = FALSE;
1806     bpp = bfp->currentBioseqPage;
1807     if (bpp != NULL && bpp->show != NULL) {
1808       bpp->show (&(bfp->bvd), FALSE);
1809     }
1810     Update ();
1811     PointerToForm (bfp->form, (Pointer) bfp->bvd.bsp);
1812     SetBioseqImportExportItems (bfp);
1813     ArrowCursor ();
1814     Update ();
1815     AdjustDynamicGraphicViewer (&(bfp->bvd));
1816   }
1817 }
1818 
ChangeBioseqDocText(PopuP p)1819 static void ChangeBioseqDocText (PopuP p)
1820 
1821 {
1822   BioseqViewFormPtr  bfp;
1823   BioseqPagePtr      bpp;
1824   Int2               firstLine = 0;
1825   Int2               firstShown = 0;
1826   Int4               horiz = 0;
1827   Int4               vert = 0;
1828   Int2               i;
1829   Int2               numItems = 0;
1830   Int4               startsAt = 0;
1831   Int4               val;
1832 
1833   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
1834   if (bfp != NULL && bfp->bvd.bsp != NULL) {
1835     WatchCursor ();
1836     bfp->bvd.moveToOldPos = FALSE;
1837     bpp = bfp->currentBioseqPage;
1838 
1839     if (Visible (bfp->bvd.text) && AllParentsVisible (bfp->bvd.text)) {
1840       /*GetOffset (bfp->bvd.text, &horiz, &vert); */
1841       Nlm_GetScrollTextOffset4 ((Nlm_GraphiC)bfp->bvd.text, &horiz, &vert);
1842 
1843     } else if (Visible (bfp->bvd.doc) && AllParentsVisible (bfp->bvd.doc)) {
1844       GetDocParams (bfp->bvd.doc, &numItems, NULL);
1845       GetScrlParams4 (bfp->bvd.doc, &vert, &firstShown, &firstLine);
1846       for (i = 1; i <= firstShown; i++) {
1847         ForceFormat (bfp->bvd.doc, i);
1848       }
1849       GetItemParams4 (bfp->bvd.doc, firstShown, &startsAt, NULL, NULL, NULL, NULL);
1850       vert = startsAt + firstLine;
1851       /*
1852       GetOffset (bfp->bvd.doc, &horiz, &vert);
1853       */
1854     }
1855 
1856     if (bpp != NULL && bpp->show != NULL) {
1857       bpp->show (&(bfp->bvd), FALSE);
1858     }
1859     Update ();
1860 
1861     val = GetValue (p);
1862     if (val == 1)
1863     {
1864       bfp->bvd.useScrollText = FALSE;
1865     }
1866     else
1867     {
1868       bfp->bvd.useScrollText = TRUE;
1869     }
1870 
1871     PointerToForm (bfp->form, (Pointer) bfp->bvd.bsp);
1872     SetBioseqImportExportItems (bfp);
1873     if (vert > 0) {
1874       if (bfp->bvd.useScrollText) {
1875         Nlm_SetScrollTextOffset4 ((Nlm_GraphiC)bfp->bvd.text, 0, vert, TRUE);
1876         /*SetOffset (bfp->bvd.text, 0, vert); */
1877       } else {
1878         GetDocParams (bfp->bvd.doc, &numItems, NULL);
1879         for (i = 1; i <= numItems && startsAt < vert; i++) {
1880           ForceFormat (bfp->bvd.doc, i);
1881           GetItemParams4 (bfp->bvd.doc, i, &startsAt, NULL, NULL, NULL, NULL);
1882         }
1883         SetScrlParams4 (bfp->bvd.doc, vert);
1884 /*        SetOffset (bfp->bvd.doc, 0, vert); */
1885       }
1886     }
1887     ArrowCursor ();
1888     Update ();
1889     AdjustDynamicGraphicViewer (&(bfp->bvd));
1890   }
1891 }
1892 
ChangeBioseqViewGroup(GrouP g)1893 static void ChangeBioseqViewGroup (GrouP g)
1894 
1895 {
1896   BioseqViewFormPtr  bfp;
1897   Int2               val;
1898 
1899   bfp = (BioseqViewFormPtr) GetObjectExtra (g);
1900   if (bfp != NULL) {
1901     val = GetValue (g);
1902     ChangeBioseqViewTabs ((VoidPtr) bfp, val - 1, 0);
1903   }
1904 }
1905 
ChangeBioseqViewPopup(PopuP p)1906 static void ChangeBioseqViewPopup (PopuP p)
1907 
1908 {
1909   BioseqViewFormPtr  bfp;
1910   Int2               val;
1911 
1912   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
1913   if (bfp != NULL) {
1914     val = GetValue (p);
1915     ChangeBioseqViewTabs ((VoidPtr) bfp, val - 1, 0);
1916   }
1917 }
1918 
ChangeBioseqItemID(GatherContextPtr gcp)1919 static Boolean ChangeBioseqItemID (GatherContextPtr gcp)
1920 
1921 {
1922   BioseqViewFormPtr  bfp;
1923 
1924   if (gcp == NULL) return TRUE;
1925   bfp = (BioseqViewFormPtr) gcp->userdata;
1926   if (bfp == NULL) return TRUE;
1927   if (gcp->thistype == OBJ_BIOSEQ) {
1928     if (bfp->bvd.bsp == (BioseqPtr) gcp->thisitem) {
1929       bfp->input_itemID = gcp->itemID;
1930       return FALSE;
1931     }
1932   }
1933   return TRUE;
1934 }
1935 
ChangeTarget(Handle targ)1936 static void ChangeTarget (Handle targ)
1937 
1938 {
1939   BioseqViewFormPtr  bfp;
1940   BioseqPagePtr      bpp;
1941   BioseqPtr          bsp;
1942   GatherScope        gs;
1943   SeqEntryPtr        sep;
1944   Int2               val;
1945 
1946   bfp = (BioseqViewFormPtr) GetObjectExtra (targ);
1947   if (bfp != NULL) {
1948     bfp->bvd.viewWholeEntity = FALSE;
1949     val = GetValue (targ);
1950     if (val == 1) {
1951       bfp->bvd.viewWholeEntity = TRUE;
1952     } else {
1953       val--;
1954     }
1955     sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
1956     if (sep != NULL) {
1957       sep = FindNthSequinEntry (sep, val);
1958       if (sep != NULL && sep->choice == 1 && sep->data.ptrvalue != NULL) {
1959         bsp = (BioseqPtr) sep->data.ptrvalue;
1960         /*
1961         if (bfp->bvd.bsp != bsp) {
1962           BioseqLock (bsp);
1963           BioseqUnlock (bfp->bvd.bsp);
1964         }
1965         */
1966         bfp->bvd.bsp = bsp;
1967         bfp->bvd.scaleNotCalculated = TRUE;
1968         bfp->bvd.moveToOldPos = FALSE;
1969         bpp = bfp->currentBioseqPage;
1970         if (bpp != NULL && bpp->show != NULL) {
1971           bpp->show (&(bfp->bvd), FALSE);
1972         }
1973         Update ();
1974         if (ISA_na (bsp->mol)) {
1975           SafeHide (bfp->protViewControl);
1976           SafeShow (bfp->nucViewControl);
1977         } else if (ISA_aa (bsp->mol)) {
1978           SafeHide (bfp->nucViewControl);
1979           SafeShow (bfp->protViewControl);
1980         }
1981         SetCurrentPagePointers (bfp);
1982         if (bfp->bvd.slp_list != NULL) {
1983           bfp->bvd.slp_list = free_slp_list (bfp->bvd.slp_list);
1984         }
1985         if (bfp->bvd.anp_node != NULL) {
1986           bfp->bvd.anp_node = FreeAlignNode (bfp->bvd.anp_node);
1987         }
1988         if (bfp->bvd.g_list != NULL) {
1989           bfp->bvd.g_list = ValNodeFreeData (bfp->bvd.g_list);
1990         }
1991         if (bfp->bvd.ftype_list != NULL) {
1992           bfp->bvd.ftype_list = ValNodeFree (bfp->bvd.ftype_list);
1993         }
1994         if (bfp->bvd.sentinelList != NULL) {
1995           bfp->bvd.sentinelList = ValNodeFreeData (bfp->bvd.sentinelList);
1996         }
1997         if (bfp->bvd.entityList != NULL) {
1998           bfp->bvd.entityList = ValNodeFree (bfp->bvd.entityList);
1999         }
2000         if (bfp->bvd.viewWholeEntity) {
2001           bfp->input_itemID = 0;
2002           PointerToForm (bfp->form, (Pointer) bfp->bvd.bsp);
2003           SetBioseqImportExportItems (bfp);
2004           SendMessageToForm (bfp->form, VIB_MSG_CHANGE);
2005           Update ();
2006           AdjustDynamicGraphicViewer (&(bfp->bvd));
2007           if (bfp->controls != NULL && bfp->updateControls != NULL) {
2008             bfp->updateControls (bfp->controls);
2009           }
2010           return;
2011         }
2012         MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
2013         gs.seglevels = 1;
2014         MemSet ((Pointer) (gs.ignore), (int)(TRUE), (size_t) (OBJ_MAX * sizeof (Boolean)));
2015         gs.ignore[OBJ_BIOSEQ] = FALSE;
2016         gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
2017         GatherEntity (bfp->input_entityID, (Pointer) bfp, ChangeBioseqItemID, &gs);
2018         PointerToForm (bfp->form, (Pointer) bfp->bvd.bsp);
2019         SetBioseqImportExportItems (bfp);
2020         SendMessageToForm (bfp->form, VIB_MSG_CHANGE);
2021         Update ();
2022         AdjustDynamicGraphicViewer (&(bfp->bvd));
2023         if (bfp->controls != NULL && bfp->updateControls != NULL) {
2024           bfp->updateControls (bfp->controls);
2025         }
2026       }
2027     }
2028   }
2029 }
2030 
2031 
SetBioseqViewTarget(BaseFormPtr fp,CharPtr seqId)2032 extern void SetBioseqViewTarget (BaseFormPtr fp, CharPtr seqId)
2033 
2034 {
2035   EnumFieldAssocPtr  ap;
2036   BioseqViewFormPtr  bfp;
2037   BioseqPtr          bsp;
2038   CharPtr            ptr;
2039   SeqIdPtr           sip;
2040   Char               str [128];
2041   Char               tmp [128];
2042   Boolean            tryJustAccn = TRUE;
2043   Int2               val, curr_val, possible_val;
2044   SeqEntryPtr        sep;
2045   Int4               s_len, l_len;
2046   CharPtr            tmp_id;
2047 
2048   bfp = (BioseqViewFormPtr) fp;
2049   if (bfp == NULL || StringHasNoText (seqId) || bfp->targetAlist == NULL) return;
2050 
2051   if (StringChr (seqId, '.') != NULL) {
2052     tryJustAccn = FALSE;
2053   }
2054   for (ap = bfp->targetAlist, val = 1; ap != NULL && ap->name != NULL; ap++, val++) {
2055     StringNCpy (str, ap->name, sizeof (str));
2056     if (StringICmp (str, seqId) == 0) {
2057       SetValue (bfp->targetControl, val);
2058       ChangeTarget ((Handle) bfp->targetControl);
2059       return;
2060     }
2061     if (tryJustAccn) {
2062       /* entered accession without version where the IDs are accession.version */
2063       ptr = StringChr (str, '.');
2064       if (ptr != NULL) {
2065         *ptr = '\0';
2066         if (StringICmp (str, seqId) == 0) {
2067           SetValue (bfp->targetControl, val);
2068           ChangeTarget ((Handle) bfp->targetControl);
2069           return;
2070         }
2071       }
2072     }
2073   }
2074 
2075   sep = GetTopSeqEntryForEntityID (fp->input_entityID);
2076   sip = CreateSeqIdFromText (seqId, sep);
2077   bsp = BioseqFind (sip);
2078   SeqIdFree (sip);
2079   if (bsp != NULL) {
2080     sip = SeqIdFindWorst (bsp->id);
2081     SeqIdWrite (sip, tmp, PRINTID_REPORT, sizeof (tmp));
2082     seqId = StringChr (tmp, '|');
2083     if (seqId == NULL) {
2084       seqId = tmp;
2085     } else {
2086       seqId++;
2087     }
2088     for (ap = bfp->targetAlist, val = 1; ap != NULL && ap->name != NULL; ap++, val++) {
2089       StringNCpy (str, ap->name, sizeof (str));
2090       if (StringICmp (str, seqId) == 0) {
2091         SetValue (bfp->targetControl, val);
2092         ChangeTarget ((Handle) bfp->targetControl);
2093         return;
2094       }
2095     }
2096   }
2097   /* no luck so far, see if this is the end of anything in the list */
2098   s_len = StringLen (seqId);
2099   for (ap = bfp->targetAlist, val = 1; ap != NULL && ap->name != NULL; ap++, val++) {
2100     StringNCpy (str, ap->name, sizeof (str));
2101     l_len = StringLen (str);
2102     if (l_len > s_len && StringICmp (str + l_len - s_len, seqId) == 0) {
2103       SetValue (bfp->targetControl, val);
2104       ChangeTarget ((Handle) bfp->targetControl);
2105       return;
2106     }
2107   }
2108   /* fooey.  look for the string anywhere in the list, starting with the next one from the current position */
2109   curr_val = GetValue (bfp->targetControl);
2110   possible_val = 0;
2111   for (ap = bfp->targetAlist, val = 1; ap != NULL && ap->name != NULL; ap++, val++) {
2112     StringNCpy (str, ap->name, sizeof (str));
2113     l_len = StringLen (str);
2114     if (l_len > s_len && StringISearch (str, seqId) != NULL) {
2115       if (val > curr_val) {
2116         SetValue (bfp->targetControl, val);
2117         ChangeTarget ((Handle) bfp->targetControl);
2118         return;
2119       } else if (possible_val == 0) {
2120         possible_val = val;
2121       }
2122     }
2123   }
2124   if (possible_val > 0) {
2125     SetValue (bfp->targetControl, possible_val);
2126     ChangeTarget ((Handle) bfp->targetControl);
2127   }
2128 
2129   /* maybe it's a BankIt ID without Seq1 */
2130   if (StringISearch (seqId, "Seq") == NULL) {
2131     tmp_id = (CharPtr) MemNew (sizeof (Char) * (StringLen (seqId) + 6));
2132     sprintf (tmp_id, "%s/Seq1", seqId);
2133     sip = CreateSeqIdFromText (tmp_id, sep);
2134     tmp_id = MemFree (tmp_id);
2135     bsp = BioseqFind (sip);
2136     SeqIdFree (sip);
2137     if (bsp != NULL) {
2138       sip = SeqIdFindWorst (bsp->id);
2139       SeqIdWrite (sip, tmp, PRINTID_REPORT, sizeof (tmp));
2140       seqId = StringChr (tmp, '|');
2141       if (seqId == NULL) {
2142         seqId = tmp;
2143       } else {
2144         seqId++;
2145       }
2146       for (ap = bfp->targetAlist, val = 1; ap != NULL && ap->name != NULL; ap++, val++) {
2147         StringNCpy (str, ap->name, sizeof (str));
2148         if (StringICmp (str, seqId) == 0) {
2149           SetValue (bfp->targetControl, val);
2150           ChangeTarget ((Handle) bfp->targetControl);
2151           return;
2152         }
2153       }
2154     }
2155   }
2156 
2157 }
2158 
GetBioseqViewTarget(BaseFormPtr fp)2159 extern BioseqPtr GetBioseqViewTarget (BaseFormPtr fp)
2160 
2161 {
2162   BioseqViewFormPtr  bfp;
2163   BioseqPtr          bsp = NULL;
2164   Int2               val;
2165   SeqEntryPtr        sep;
2166 
2167   bfp = (BioseqViewFormPtr) fp;
2168   if (bfp == NULL || bfp->targetControl == NULL) return NULL;
2169 
2170   val = GetValue (bfp->targetControl);
2171   if (val > 1) {
2172     val--;
2173     sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
2174     if (sep != NULL) {
2175       sep = FindNthSequinEntry (sep, val);
2176       if (sep != NULL && sep->choice == 1 && sep->data.ptrvalue != NULL) {
2177         bsp = (BioseqPtr) sep->data.ptrvalue;
2178       }
2179     }
2180   }
2181   return bsp;
2182 }
2183 
GetBioseqViewPtrFromBaseFormPtr(BaseFormPtr fp)2184 extern BioseqViewPtr GetBioseqViewPtrFromBaseFormPtr (BaseFormPtr fp)
2185 
2186 {
2187   BioseqViewFormPtr  bfp;
2188   bfp = (BioseqViewFormPtr) fp;
2189   if (bfp == NULL) return NULL;
2190   return (&(bfp->bvd));
2191 }
2192 
ChangeStyle(PopuP p)2193 static void ChangeStyle (PopuP p)
2194 
2195 {
2196   BioseqViewFormPtr  bfp;
2197 
2198   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
2199   if (bfp != NULL) {
2200     bfp->bvd.moveToOldPos = TRUE;
2201     PointerToForm (bfp->form, bfp->bvd.bsp);
2202     Update ();
2203     AdjustDynamicGraphicViewer (&(bfp->bvd));
2204   }
2205 }
2206 
ChangeScale(PopuP p)2207 static void ChangeScale (PopuP p)
2208 
2209 {
2210   BioseqViewFormPtr  bfp;
2211 
2212   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
2213   if (bfp != NULL) {
2214     bfp->bvd.moveToOldPos = TRUE;
2215     PointerToForm (bfp->form, bfp->bvd.bsp);
2216     Update ();
2217     AdjustDynamicGraphicViewer (&(bfp->bvd));
2218   }
2219 }
2220 
ChangeNewStyle(PopuP p)2221 static void ChangeNewStyle (PopuP p)
2222 
2223 {
2224   BioseqViewFormPtr  bfp;
2225 
2226   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
2227   if (bfp != NULL) {
2228     bfp->bvd.moveToOldPos = TRUE;
2229     PointerToForm (bfp->form, bfp->bvd.bsp);
2230     Update ();
2231     AdjustDynamicGraphicViewer (&(bfp->bvd));
2232   }
2233 }
2234 
ChangeNewFilter(PopuP p)2235 static void ChangeNewFilter (PopuP p)
2236 
2237 {
2238   BioseqViewFormPtr  bfp;
2239 
2240   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
2241   if (bfp != NULL) {
2242     bfp->bvd.moveToOldPos = TRUE;
2243     PointerToForm (bfp->form, bfp->bvd.bsp);
2244     Update ();
2245     AdjustDynamicGraphicViewer (&(bfp->bvd));
2246   }
2247 }
2248 
ChangeNewScale(PopuP p)2249 static void ChangeNewScale (PopuP p)
2250 
2251 {
2252   BioseqViewFormPtr  bfp;
2253 
2254   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
2255   if (bfp != NULL) {
2256     bfp->bvd.moveToOldPos = TRUE;
2257     PointerToForm (bfp->form, bfp->bvd.bsp);
2258     Update ();
2259     AdjustDynamicGraphicViewer (&(bfp->bvd));
2260   }
2261 }
2262 
ChangeNewLayout(ChoicE c)2263 static void ChangeNewLayout (ChoicE c)
2264 
2265 {
2266   BioseqViewFormPtr  bfp;
2267 
2268 #ifdef WIN_MAC
2269   bfp = currentFormDataPtr;
2270 #else
2271   bfp = (BioseqViewFormPtr) GetObjectExtra (c);
2272 #endif
2273   if (bfp != NULL) {
2274     bfp->bvd.moveToOldPos = TRUE;
2275     PointerToForm (bfp->form, bfp->bvd.bsp);
2276     Update ();
2277     AdjustDynamicGraphicViewer (&(bfp->bvd));
2278   }
2279 }
2280 
2281 extern void CreateNewLayoutMenu (MenU m, BaseFormPtr bp);
CreateNewLayoutMenu(MenU m,BaseFormPtr bp)2282 extern void CreateNewLayoutMenu (MenU m, BaseFormPtr bp)
2283 
2284 {
2285   BioseqViewFormPtr  bfp;
2286   Int2               j;
2287   CharPtr PNTR       layoutnames;
2288 
2289   bfp = (BioseqViewFormPtr) bp;
2290   bfp->bvd.newGphLayout = ChoiceGroup (m, ChangeNewLayout);
2291   SetObjectExtra (bfp->bvd.newGphLayout, bfp, NULL);
2292   layoutnames = GetLayoutNameList ();
2293   for (j = 0; layoutnames [j] != NULL; j++) {
2294     ChoiceItem (bfp->bvd.newGphLayout, layoutnames [j]);
2295   }
2296   SetValue (bfp->bvd.newGphLayout, 1);
2297 }
2298 
ChangeSalsaControls(PopuP p)2299 static void ChangeSalsaControls (PopuP p)
2300 
2301 {
2302   BioseqViewFormPtr  bfp;
2303 
2304   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
2305   if (bfp != NULL) {
2306     bfp->bvd.moveToOldPos = TRUE;
2307     PointerToForm (bfp->form, bfp->bvd.bsp);
2308     Update ();
2309     AdjustDynamicGraphicViewer (&(bfp->bvd));
2310   }
2311 }
2312 
ChangeSeqViewControls(PopuP p)2313 static void ChangeSeqViewControls (PopuP p)
2314 
2315 {
2316   BioseqViewFormPtr  bfp;
2317 
2318   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
2319   if (bfp == NULL) return;
2320 
2321   bfp->bvd.moveToOldPos = TRUE;
2322   PointerToForm (bfp->form, bfp->bvd.bsp);
2323   Update ();
2324 }
2325 
ChangeFlatFileMode(PopuP p)2326 static void ChangeFlatFileMode (PopuP p)
2327 
2328 {
2329   BioseqViewFormPtr  bfp;
2330 
2331   bfp = (BioseqViewFormPtr) GetObjectExtra (p);
2332   if (bfp != NULL) {
2333     bfp->bvd.moveToOldPos = TRUE;
2334     PointerToForm (bfp->form, bfp->bvd.bsp);
2335     Update ();
2336     AdjustDynamicGraphicViewer (&(bfp->bvd));
2337   }
2338 }
2339 
DuplicateViewProc(ButtoN b)2340 static void DuplicateViewProc (ButtoN b)
2341 
2342 {
2343   BioseqViewFormPtr  bfp;
2344   Int2               handled;
2345   Uint4              itemID;
2346   SeqViewProcsPtr    svpp;
2347 
2348   bfp = (BioseqViewFormPtr) GetObjectExtra (b);
2349   if (bfp == NULL) return;
2350   if (bfp->input_itemtype == OBJ_BIOSEQ) {
2351     WatchCursor ();
2352     itemID = bfp->input_itemID;
2353     if (itemID == 0) {
2354       itemID = 1;
2355     }
2356     svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
2357     if (svpp != NULL) {
2358       svpp->forceSeparateViewer = TRUE;
2359     }
2360     handled = GatherProcLaunch (OMPROC_VIEW, FALSE, bfp->input_entityID, itemID,
2361                                 OBJ_BIOSEQ, 0, 0, OBJ_BIOSEQ, 0);
2362     ArrowCursor ();
2363     if (handled != OM_MSG_RET_DONE || handled == OM_MSG_RET_NOPROC) {
2364       Message (MSG_ERROR, "Unable to launch additional viewer.");
2365     }
2366   } else if (bfp->input_itemtype == OBJ_MEDLINE_ENTRY) {
2367     WatchCursor ();
2368     itemID = bfp->input_itemID;
2369     if (itemID == 0) {
2370       itemID = 1;
2371     }
2372     handled = GatherProcLaunch (OMPROC_VIEW, FALSE, bfp->input_entityID, itemID,
2373                                 OBJ_MEDLINE_ENTRY, 0, 0, OBJ_MEDLINE_ENTRY, 0);
2374     ArrowCursor ();
2375     if (handled != OM_MSG_RET_DONE || handled == OM_MSG_RET_NOPROC) {
2376       Message (MSG_ERROR, "Unable to launch additional viewer.");
2377     }
2378   }
2379 }
2380 
CleanupBioseqForm(GraphiC g,VoidPtr data)2381 static void CleanupBioseqForm (GraphiC g, VoidPtr data)
2382 
2383 {
2384   BioseqViewFormPtr  bfp;
2385   Uint2              userkey, entityID;
2386   ValNodePtr         vnp;
2387 
2388   bfp = (BioseqViewFormPtr) data;
2389   if (bfp != NULL) {
2390     WatchCursor ();
2391     /*
2392     BioseqUnlock (bfp->bvd.bsp);
2393     */
2394     entityID = bfp->input_entityID;
2395     if (bfp->input_entityID > 0 && bfp->userkey > 0) {
2396       userkey = bfp->userkey;
2397       bfp->userkey = 0;
2398       ObjMgrFreeUserData (bfp->input_entityID, bfp->procid, bfp->proctype, userkey);
2399       /* this may trigger another remove, hence bfp->userkey first set to 0 */
2400       for (vnp = bfp->bvd.entityList; vnp != NULL; vnp = vnp->next) {
2401         if (bfp->input_entityID != (Uint2) vnp->data.intvalue) {
2402           ObjMgrFreeUserData ((Uint2) vnp->data.intvalue, bfp->procid, bfp->proctype, userkey);
2403         }
2404       }
2405     }
2406     bfp->bvd.bsplist = UnlockFarComponents (bfp->bvd.bsplist);
2407     bfp->bvd.pict = DeletePicture (bfp->bvd.pict);
2408     if (bfp->bvd.slp_list != NULL) {
2409       bfp->bvd.slp_list = free_slp_list (bfp->bvd.slp_list);
2410     }
2411     if (bfp->bvd.anp_node != NULL) {
2412       bfp->bvd.anp_node = FreeAlignNode (bfp->bvd.anp_node);
2413     }
2414     if (bfp->bvd.g_list != NULL) {
2415       bfp->bvd.g_list = ValNodeFreeData (bfp->bvd.g_list);
2416     }
2417     if (bfp->bvd.ftype_list != NULL) {
2418       bfp->bvd.ftype_list = ValNodeFree (bfp->bvd.ftype_list);
2419     }
2420     if (bfp->bvd.sentinelList != NULL) {
2421       bfp->bvd.sentinelList = ValNodeFreeData (bfp->bvd.sentinelList);
2422     }
2423     if (bfp->bvd.entityList != NULL) {
2424       bfp->bvd.entityList = ValNodeFree (bfp->bvd.entityList);
2425     }
2426     if (bfp->cleanupObjectPtr && bfp->objectDataPtr != NULL) {
2427       SeqEntryFree ((SeqEntryPtr) bfp->objectDataPtr);
2428     }
2429     bfp->bioseqNucPageList = BioseqPageListFree (bfp->bioseqNucPageList);
2430     bfp->bioseqProtPageList = BioseqPageListFree (bfp->bioseqProtPageList);
2431     bfp->targetAlist = FreeEnumFieldAlist (bfp->targetAlist);
2432 
2433     /* remove orphaned far components */
2434     ObjMgrFreeCache (OBJ_MAX);
2435     FreeSeqIdGiCache ();
2436 
2437     /* if the only remaining views for this entity ID are desktop views, get rid
2438      * of the desktop views as well
2439      */
2440     if (DeleteRemainingViews(entityID)) {
2441         VSeqMgrShow();
2442     }
2443 
2444     ArrowCursor ();
2445 
2446   }
2447   StdCleanupFormProc (g, data);
2448 }
2449 
WriteEntityProc(Uint2 entityID,CharPtr path)2450 static void WriteEntityProc (Uint2 entityID, CharPtr path)
2451 
2452 {
2453   if (entityID > 0 && path != NULL && *path != '\0') {
2454     ObjMgrSetDirtyFlag (entityID, FALSE);
2455   }
2456 }
2457 
CloseViewFormProc(WindoW w)2458 static void CloseViewFormProc (WindoW w)
2459 
2460 {
2461   BioseqViewFormPtr  bfp;
2462   Char               path [PATH_MAX];
2463   MsgAnswer          response;
2464 
2465   bfp = (BioseqViewFormPtr) GetObjectExtra (w);
2466   if (bfp != NULL) {
2467     if (ObjMgrGetDirtyFlag (bfp->input_entityID)) {
2468       response = Message (MSG_YNC, "Do you wish to save the changes?");
2469       if (response == ANS_YES) {
2470         if (GetOutputFileName (path, sizeof (path), NULL)) {
2471           WriteEntityProc (bfp->input_entityID, path);
2472         } else {
2473           return;
2474         }
2475       } else if (response == ANS_CANCEL) {
2476         return;
2477       }
2478     }
2479   }
2480   RemoveSeqEntryViewer ((ForM) w);
2481 }
2482 
ExportBioseqViewForm(ForM f,CharPtr filename)2483 static Boolean ExportBioseqViewForm (ForM f, CharPtr filename)
2484 
2485 {
2486   ExportBioseqViewFormToFile (GetObjectExtra (f), filename);
2487   return TRUE;
2488 }
2489 
BioseqFormMessage(ForM f,Int2 mssg)2490 static void BioseqFormMessage (ForM f, Int2 mssg)
2491 
2492 {
2493   BioseqViewFormPtr  bfp;
2494   BioseqPagePtr      bpp;
2495   SeqViewProcsPtr    svpp;
2496 
2497   bfp = (BioseqViewFormPtr) GetObjectExtra (f);
2498   if (bfp != NULL) {
2499     switch (mssg) {
2500       case VIB_MSG_REDRAW :
2501         svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
2502         if (svpp != NULL) {
2503           bfp->bvd.displayFont = svpp->displayFont;
2504           bpp = bfp->currentBioseqPage;
2505           if (bpp != NULL && bpp->show != NULL) {
2506             bpp->show (&(bfp->bvd), FALSE);
2507           }
2508           PointerToForm (bfp->form, bfp->bvd.bsp);
2509           Update ();
2510           AdjustDynamicGraphicViewer (&(bfp->bvd));
2511         }
2512         break;
2513       case VIB_MSG_COPY :
2514         CopyBioseqViewFormToClipboard (bfp);
2515         break;
2516       case VIB_MSG_EXPORT :
2517         ExportBioseqViewForm (f, NULL);
2518         break;
2519       case VIB_MSG_PRINT :
2520         PrintBioseqViewForm (bfp);
2521         break;
2522       default :
2523         if (bfp->appmessage != NULL) {
2524           bfp->appmessage (f, mssg);
2525         }
2526         break;
2527     }
2528   }
2529 }
2530 
2531 /*
2532 Nlm_LaunchWebPage tries to launch a web page given by the complete url
2533 (including "http://")
2534 */
2535 
Nlm_LaunchWebPage(Char * url)2536 NLM_EXTERN void Nlm_LaunchWebPage (Char *url)
2537 {
2538 #ifdef WIN_MOTIF
2539     CharPtr            argv [8];
2540     int child;
2541 #endif
2542     if(url == NULL) return;
2543 #ifdef WIN_MAC
2544     Nlm_SendURLAppleEvent (url, "MOSS", NULL);
2545 #endif
2546 #ifdef WIN_MSWIN
2547     if (! Nlm_MSWin_OpenDocument (url)) {
2548         Message (MSG_POST, "Unable to launch browser");
2549     }
2550 #endif
2551 #ifdef WIN_MOTIF
2552   argv [0] = "netscape";
2553   argv [1] = url;
2554   argv [2] = NULL;
2555   child = fork();
2556   if(child == 0) {
2557      if (execvp ("netscape", argv) == -1) {
2558         Message (MSG_POST, "Unable to launch netscape");
2559         exit(-1);
2560     }
2561   }
2562 #endif
2563 }
2564 
2565 /*
2566 static void LaunchPubSeqArticle (ButtoN b)
2567 
2568 {
2569 #ifndef WIN_MAC
2570   CharPtr            argv [8];
2571 #endif
2572   BioseqViewFormPtr  bfp;
2573   CharPtr            browser;
2574   Char               str [256];
2575 #ifdef WIN_MOTIF
2576   NS_Window          window = NULL;
2577 #endif
2578 
2579   bfp = (BioseqViewFormPtr) GetObjectExtra (b);
2580   if (bfp == NULL) return;
2581   if (bfp->docuid < 1) return;
2582   browser = GetAppProperty ("MedviewBrowserPath");
2583   sprintf (str,
2584            "http://www.ncbi.nlm.nih.gov/htbin-post/Entrez/query?db=s&form=6&uid=%ld&Dopt=g",
2585            (long) bfp->docuid);
2586 #ifdef WIN_MAC
2587   if (browser == NULL || StringHasNoText (browser)) {
2588     Nlm_SendURLAppleEvent (str, "MOSS", NULL);
2589   } else {
2590     Nlm_SendURLAppleEvent (str, NULL, browser);
2591   }
2592 #endif
2593 #ifdef WIN_MSWIN
2594   argv [0] = str;
2595   argv [1] = NULL;
2596   if (browser != NULL && (! StringHasNoText (browser))) {
2597     if (! Execv (browser, argv)) {
2598       Message (MSG_POST, "Unable to launch %s", browser);
2599     }
2600   } else {
2601     if (! Nlm_MSWin_OpenDocument (str)) {
2602       Message (MSG_POST, "Unable to launch browser");
2603     }
2604   }
2605 #endif
2606 #ifdef WIN_MOTIF
2607   argv [0] = str;
2608   argv [1] = NULL;
2609   if (browser != NULL && (! StringHasNoText (browser))) {
2610     if (! Execv (browser, argv)) {
2611       Message (MSG_POST, "Unable to launch %s", browser);
2612     }
2613   } else {
2614     if (! NS_OpenURL (&window, str, NULL, TRUE)) {
2615       Message (MSG_POST, "Unable to launch netscape");
2616     }
2617     NS_WindowFree (window);
2618   }
2619 #endif
2620 }
2621 */
2622 
LaunchPubSeqArticle(ButtoN b)2623 static void LaunchPubSeqArticle (ButtoN b)
2624 
2625 {
2626   BioseqViewFormPtr  bfp;
2627   BioseqPtr          bsp;
2628 
2629   bfp = (BioseqViewFormPtr) GetObjectExtra (b);
2630   if (bfp == NULL) return;
2631   if (bfp->docuid < 1) return;
2632   bsp = bfp->bvd.bsp;
2633   if (bsp == NULL) return;
2634   if (ISA_na (bsp->mol)) {
2635     LaunchEntrezURL ("Nucleotide", bfp->docuid, "GenBank");
2636   } else if (ISA_aa (bsp->mol)) {
2637     LaunchEntrezURL ("Protein", bfp->docuid, "GenPept");
2638   }
2639 }
2640 
CreateViewControl(GrouP g,BioseqViewFormPtr bfp,SeqViewProcsPtr svpp,BioseqPagePtr bpp,Int2 page,Int2 pixwidth)2641 static Handle CreateViewControl (GrouP g, BioseqViewFormPtr bfp,
2642                                  SeqViewProcsPtr svpp, BioseqPagePtr bpp,
2643                                  Int2 page, Int2 pixwidth)
2644 
2645 
2646 {
2647   Int2          count;
2648   Int2          j;
2649   GrouP         k;
2650   PopuP         pops;
2651   PrompT        ppt;
2652   Int2          radiowidth;
2653   GrouP         rads;
2654   DialoG        tbs;
2655   CharPtr PNTR  titles;
2656   BioseqPagePtr tmp;
2657   Int2          wid;
2658 
2659   if (bfp != NULL && svpp != NULL && bpp != NULL) {
2660     count = 0;
2661     for (tmp = bpp; tmp != NULL; tmp = tmp->next) {
2662       count++;
2663     }
2664     titles = MemNew (sizeof (CharPtr PNTR) * (count + 1));
2665     count = 0;
2666     for (tmp = bpp; tmp != NULL; tmp = tmp->next) {
2667       titles [count] = tmp->label;
2668       count++;
2669     }
2670     switch (svpp->useFolderTabs) {
2671       case CHANGE_VIEW_NOTABS :
2672         MemFree (titles);
2673         return NULL;
2674       case CHANGE_VIEW_FOLDERTABS :
2675         tbs = CreateFolderTabs (g, titles, page,
2676                                 0, 0, SYSTEM_FOLDER_TAB,
2677                                 ChangeBioseqViewTabs, (Pointer) bfp);
2678         MemFree (titles);
2679         return (Handle) tbs;
2680       case CHANGE_VIEW_TEXTTABS :
2681         tbs = CreateTextTabs (g, titles, page,
2682                               0, 0, SYSTEM_TEXT_TAB,
2683                               ChangeBioseqViewTabs, (Pointer) bfp);
2684         MemFree (titles);
2685         return (Handle) tbs;
2686       case CHANGE_VIEW_RADIOBUTTONS :
2687         k = HiddenGroup (g, -3, 0, NULL);
2688         ppt = StaticPrompt (k, "Format:", 0, 0, programFont, 'l');
2689         SelectFont (programFont);
2690         pixwidth -= StringWidth ("Format:");
2691         SelectFont (systemFont);
2692         wid = 0;
2693         radiowidth = 0;
2694         for (j = 0; titles [j] != NULL; j++) {
2695           wid += StringWidth (titles [j]);
2696 #ifdef WIN_MOTIF
2697           pixwidth -= 25;
2698 #else
2699           pixwidth -= 20;
2700 #endif
2701           radiowidth++;
2702         }
2703         if (wid > pixwidth) {
2704           radiowidth = (radiowidth + 1) / 2;
2705         }
2706         rads = HiddenGroup (k, radiowidth, 0, ChangeBioseqViewGroup);
2707         SetObjectExtra (rads, (Pointer) bfp, NULL);
2708         for (j = 0; titles [j] != NULL; j++) {
2709           RadioButton (rads, titles [j]);
2710         }
2711         SetValue (rads, page + 1);
2712         AlignObjects (ALIGN_MIDDLE, (HANDLE) ppt, (HANDLE) rads, NULL);
2713         MemFree (titles);
2714         return (Handle) rads;
2715       case CHANGE_VIEW_POPUP :
2716         k = HiddenGroup (g, -3, 0, NULL);
2717         ppt = StaticPrompt (k, "Format", 0, 0, programFont, 'l');
2718         pops = PopupList (k, TRUE, ChangeBioseqViewPopup);
2719         SetObjectExtra (pops, (Pointer) bfp, NULL);
2720         for (j = 0; titles [j] != NULL; j++) {
2721           PopupItem (pops, titles [j]);
2722         }
2723         SetValue (pops, page + 1);
2724         AlignObjects (ALIGN_MIDDLE, (HANDLE) ppt, (HANDLE) pops, NULL);
2725         MemFree (titles);
2726         return (Handle) pops;
2727       default :
2728         break;
2729     }
2730     MemFree (titles);
2731   }
2732   return NULL;
2733 }
2734 
BioseqViewFormActivate(WindoW w)2735 static void BioseqViewFormActivate (WindoW w)
2736 
2737 {
2738   BioseqViewFormPtr  bfp;
2739 
2740   bfp = (BioseqViewFormPtr) GetObjectExtra (w);
2741   if (bfp != NULL) {
2742     if (bfp->activate != NULL) {
2743       bfp->activate (w);
2744     }
2745     SetBioseqImportExportItems (bfp);
2746     if (bfp->bvd.legendOK) {
2747       SafeEnable (bfp->bvd.legendItem);
2748     } else {
2749       SafeDisable (bfp->bvd.legendItem);
2750     }
2751   }
2752 }
2753 
CopyBioseqReportSpecs(BioseqPagePtr bpp,BioseqPagePtr PNTR head,Int4 length,Boolean hasAlignments,Boolean isGenome,Boolean nucOK,Boolean protOK)2754 static void CopyBioseqReportSpecs (BioseqPagePtr bpp, BioseqPagePtr PNTR head,
2755                                    Int4 length, Boolean hasAlignments,
2756                                    Boolean isGenome, Boolean nucOK, Boolean protOK)
2757 
2758 {
2759   Boolean  okay;
2760 
2761   if (bpp == NULL || head == NULL) return;
2762   while (bpp != NULL) {
2763     okay = FALSE;
2764     if (isGenome) {
2765       if (bpp->genomeOK) {
2766         okay = TRUE;
2767       }
2768     } else if (nucOK && bpp->nucOK) {
2769       okay = TRUE;
2770     } else if (protOK && bpp->protOK) {
2771       okay = TRUE;
2772     }
2773     if (okay) {
2774       if (bpp->maxLength < 0 || length <= bpp->maxLength) {
2775         if (hasAlignments || (! bpp->needAlignment)) {
2776           AddBioseqPageToList (head, bpp);
2777         }
2778       }
2779     }
2780     bpp = bpp->next;
2781   }
2782 }
2783 
HasAlignments(BioseqPtr bsp)2784 static Boolean HasAlignments (BioseqPtr bsp)
2785 
2786 {
2787   return TRUE;
2788 }
2789 
2790 /*
2791 extern void Nlm_DisplayEnvironmentVariables (void);
2792 static void EnviroProc (ButtoN b)
2793 
2794 {
2795   Nlm_DisplayEnvironmentVariables ();
2796 }
2797 */
2798 
CreateNewSeqEntryViewFormEx(Int2 left,Int2 top,CharPtr title,BioseqPtr bsp,SeqViewProcsPtr svpp,Uint2 entD,Uint4 itemID,Uint2 itemtype,Boolean smart)2799 static ForM LIBCALL CreateNewSeqEntryViewFormEx (Int2 left, Int2 top, CharPtr title,
2800                                                  BioseqPtr bsp, SeqViewProcsPtr svpp,
2801                                                  Uint2 entD, Uint4 itemID, Uint2 itemtype,
2802                                                  Boolean smart)
2803 
2804 {
2805   ButtoN               b;
2806   BioseqViewFormPtr    bfp;
2807   BioseqPagePtr        bpp;
2808   WndActnProc          close;
2809   Int4                 count;
2810   GrouP                d;
2811   ButtoN               dp;
2812   Int2                 delta;
2813   Uint2                entityID;
2814   FonT                 fnt;
2815   GrouP                g;
2816   GrouP                h;
2817   Boolean              hasAlignments;
2818   Int2                 i;
2819   Boolean              is_nc = FALSE;
2820   Int2                 j;
2821   GrouP                k;
2822   Int4                 length;
2823   SeqViewFetchAlignsProc  makeAlignBtn = NULL;
2824   SeqViewControlsProc  makeControls = NULL;
2825   Int2                 mssg;
2826   Boolean              newGraphicalViewer = FALSE;
2827   GrouP                newPnlGrp;
2828   Int2                 numStyles;
2829   Int2                 pixheight;
2830   Int2                 pixwidth;
2831   GrouP                pnlGrp;
2832   PrompT               ppt;
2833   PoinT                pt;
2834   Int2                 pty;
2835   GrouP                q;
2836   RecT                 r;
2837   RecT                 r1;
2838   RecT                 r2;
2839   RecT                 r3;
2840   GrouP                s;
2841   SeqEntryPtr          sep;
2842   SeqIdPtr             sip;
2843   CharPtr              str;
2844   CharPtr              styleName;
2845   TextSeqIdPtr         tsip;
2846   Int4                 val;
2847   WindoW               w;
2848   PopuP                x;
2849   GrouP                y;
2850   ButtoN               z;
2851 
2852   w = NULL;
2853   bfp = (BioseqViewFormPtr) MemNew (sizeof (BioseqViewForm));
2854   if (bfp != NULL /* && bsp != NULL */ ) {
2855     close = CloseViewFormProc;
2856     if (svpp == NULL) {
2857       svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
2858     }
2859     if (svpp != NULL && svpp->closeForm != NULL) {
2860       close = svpp->closeForm;
2861     }
2862     w = DocumentWindow (left, top, -10, -10, title,
2863                         close, ResizeViewForm);
2864     SetObjectExtra (w, bfp, CleanupBioseqForm);
2865     bfp->form = (ForM) w;
2866     bfp->actproc = NULL;
2867     bfp->toform = BioseqPtrToBioseqForm;
2868     bfp->exportform = ExportBioseqViewForm;
2869     bfp->formmessage = BioseqFormMessage;
2870 
2871     bfp->input_entityID = entD;
2872     bfp->input_itemID = itemID;
2873     bfp->input_itemtype = itemtype;
2874     bfp->this_itemtype = OBJ_BIOSEQ;
2875     if (bsp != NULL) {
2876       bfp->this_subtype = bsp->repr;
2877       for (sip = bsp->id; sip != NULL; sip = sip->next) {
2878         if (sip->choice != SEQID_OTHER) continue;
2879         tsip = (TextSeqIdPtr) sip->data.ptrvalue;
2880         if (tsip == NULL) continue;
2881         if (StringNCmp (tsip->accession, "NC_", 3) == 0) {
2882           is_nc = TRUE;
2883         }
2884       }
2885     } else {
2886       bfp->this_subtype = Seq_repr_raw;
2887     }
2888 
2889     bfp->bvd.form = bfp->form;
2890     bfp->bvd.bsp = bsp;
2891     /*
2892     BioseqLock (bsp);
2893     */
2894     bfp->pubseq = NULL;
2895 
2896     if (svpp != NULL) {
2897       bfp->cleanupObjectPtr = svpp->cleanupObjectPtr;
2898       bfp->appmessage = svpp->handleMessages;
2899       bfp->activateForm = svpp->activateForm;
2900 
2901       if (svpp->allowScrollText) {
2902         bfp->bvd.useScrollText = svpp->startInScrollText;
2903       }
2904       bfp->bvd.launchEditors = svpp->launchEditors;
2905       bfp->bvd.launchSubviewers = svpp->launchSubviewers;
2906       bfp->bvd.sendSelectMessages = svpp->sendSelectMessages;
2907       bfp->bvd.highlightSelections = svpp->highlightSelections;
2908       bfp->bvd.hasTargetControl = svpp->hasTargetControl;
2909       bfp->bvd.displayFont = svpp->displayFont;
2910 
2911       if (! StringHasNoText (svpp->filepath)) {
2912         bfp->filepath = StringSave (svpp->filepath);
2913       }
2914 
2915       if (bsp != NULL) {
2916         hasAlignments = HasAlignments (bsp);
2917         entityID = ObjMgrGetEntityIDForPointer (bsp);
2918         sep = GetTopSeqEntryForEntityID (entityID);
2919         bfp->bvd.isGenome = IsAGenomeRecord (sep);
2920         length = bsp->length;
2921       } else {
2922         hasAlignments = TRUE;
2923         entityID = 0;
2924         sep = NULL;
2925         bfp->bvd.isGenome = FALSE;
2926         length = 0;
2927       }
2928       CopyBioseqReportSpecs (svpp->pageSpecs, &(bfp->bioseqNucPageList),
2929                              length, hasAlignments, bfp->bvd.isGenome,
2930                              TRUE, FALSE);
2931       CopyBioseqReportSpecs (svpp->pageSpecs, &(bfp->bioseqProtPageList),
2932                              length, hasAlignments, /* bfp->bvd.isGenome */ FALSE,
2933                              FALSE, TRUE);
2934       if (bfp->bioseqNucPageList == NULL && bfp->bioseqProtPageList == NULL) {
2935         Message (MSG_ERROR, "No acceptable report forms are currently registered");
2936       }
2937       makeControls = svpp->makeControls;
2938       bfp->updateControls = svpp->updateControls;
2939       makeAlignBtn = svpp->makeAlignBtn;
2940       bfp->updateCounts = svpp->updateCounts;
2941     }
2942 
2943     if (svpp != NULL && svpp->createMenus != NULL) {
2944       svpp->createMenus (w);
2945     }
2946 
2947     g = HiddenGroup (w, -1, 0, NULL);
2948     SetObjectExtra (g, bfp, NULL);
2949     SetGroupSpacing (g, 3, 10);
2950 
2951     /*
2952     if (svpp != NULL && svpp->createToolBar != NULL) {
2953       svpp->createToolBar (g);
2954     }
2955     */
2956 
2957     fnt = programFont;
2958     if (bfp->bvd.displayFont != NULL) {
2959       fnt = bfp->bvd.displayFont;
2960     }
2961     SelectFont (fnt);
2962     pixwidth = MIN ((Int2) (80 * CharWidth ('0') + 18),
2963                     (Int2) (screenRect.right - screenRect.left - 20));
2964     SelectFont (systemFont);
2965     pixheight = 14 * stdLineHeight;
2966     bfp->currentBioseqPage = NULL;
2967     bfp->currentNucPage = 0;
2968     bfp->currentProtPage = 0;
2969     bfp->targetAlist = NULL;
2970 
2971     /*
2972     bfp->ffstyle = GENBANK_STYLE;
2973     bfp->anp_node = NULL;
2974     if (Nlm_GetAppProperty ("SequinUseEMBLStyle") != NULL) {
2975       bfp->ffstyle = EMBL_STYLE;
2976     } else if (Nlm_GetAppProperty ("SequinUseDDBJStyle") != NULL) {
2977       bfp->ffstyle = DDBJ_STYLE;
2978     }
2979     */
2980     b = NULL;
2981     k = NULL;
2982     if (svpp != NULL) {
2983       if (bfp->bvd.hasTargetControl) {
2984         k = HiddenGroup (g, -4, 0, NULL);
2985         ppt = StaticPrompt (k, "Target Sequence", 0, 0, programFont, 'l');
2986         count = 0;
2987         if (bsp != NULL) {
2988           entityID = ObjMgrGetEntityIDForPointer (bfp->bvd.bsp);
2989           sep = GetTopSeqEntryForEntityID (entityID);
2990           count = SequinEntryCount (sep);
2991         }
2992         if (bsp != NULL && count < 32 && (! smart)) {
2993           bfp->usePopupForTarget = TRUE;
2994           bfp->targetControl = (Handle) PopupList (k, TRUE, (PupActnProc) ChangeTarget);
2995         } else {
2996           bfp->usePopupForTarget = FALSE;
2997           bfp->targetControl = (Handle) SingleList (k, 14, 3, (LstActnProc) ChangeTarget);
2998         }
2999         SetObjectExtra (bfp->targetControl, (Pointer) bfp, NULL);
3000         val = PopulateTarget (bfp);
3001         SetValue (bfp->targetControl, (Int2) val + 1);
3002         bfp->pubseq = PushButton (k, "PubMed", LaunchPubSeqArticle);
3003         SetObjectExtra (bfp->pubseq, (Pointer) bfp, NULL);
3004         Hide (bfp->pubseq);
3005         if (svpp->hasDoneButton) {
3006           b = PushButton (k, "Done", StdSendAcceptButtonMessageProc);
3007           SetObjectExtra (b, bfp, NULL);
3008         }
3009         AlignObjects (ALIGN_VERTICAL, (HANDLE) ppt, (HANDLE) bfp->targetControl, NULL);
3010         GetPosition (bfp->targetControl, &r1);
3011         GetPosition (bfp->pubseq, &r2);
3012         delta = (r1.bottom - r1.top) - (r2.bottom - r2.top);
3013         if (delta > 0) {
3014           OffsetRect (&r2, 0, delta / 2);
3015           SetPosition (bfp->pubseq, &r2);
3016           AdjustPrnt (bfp->pubseq, &r2, FALSE);
3017         }
3018         GetPosition (b, &r2);
3019         delta = (r1.bottom - r1.top) - (r2.bottom - r2.top);
3020         if (delta > 0) {
3021           OffsetRect (&r2, 0, delta / 2);
3022           SetPosition (b, &r2);
3023           AdjustPrnt (b, &r2, FALSE);
3024         }
3025         /* PushButton (k, "Enviro", EnviroProc); */
3026       }
3027       bfp->currentNucPage = svpp->initNucPage;
3028       bfp->currentProtPage = svpp->initProtPage;
3029 
3030       str = NULL;
3031       bpp = NULL;
3032       if (bfp->bvd.isGenome) {
3033         if (svpp->initGenomeLabel != NULL) {
3034           bpp = bfp->bioseqNucPageList;
3035           str = svpp->initGenomeLabel;
3036           if (is_nc) {
3037             str = "GenBank";
3038           }
3039         }
3040       } else {
3041         if (svpp->initNucLabel != NULL) {
3042           bpp = bfp->bioseqNucPageList;
3043           str = svpp->initNucLabel;
3044           if (bsp != NULL && bsp->length > 350000) {
3045             /*
3046             if (is_nc) {
3047               str = "GenBank";
3048             } else {
3049               str = "Graphic";
3050             }
3051             */
3052           }
3053         }
3054       }
3055       if (str != NULL && bpp != NULL) {
3056         j = 0;
3057         while (bpp != NULL) {
3058           if (StringICmp (bpp->label, str) == 0) {
3059             bfp->currentNucPage = j;
3060           }
3061           bpp = bpp->next;
3062           j++;
3063         }
3064       }
3065       if (svpp->initProtLabel != NULL) {
3066         bpp = bfp->bioseqProtPageList;
3067         str = svpp->initProtLabel;
3068         j = 0;
3069         while (bpp != NULL) {
3070           if (StringICmp (bpp->label, str) == 0) {
3071             bfp->currentProtPage = j;
3072           }
3073           bpp = bpp->next;
3074           j++;
3075         }
3076       }
3077 
3078       k = HiddenGroup (g, -2, 0, NULL);
3079       if (bfp->bvd.hasTargetControl || bsp == NULL) {
3080         q = HiddenGroup (k, 0, 0, NULL);
3081         bfp->nucViewControl = CreateViewControl (q, bfp, svpp, bfp->bioseqNucPageList,
3082                                                  bfp->currentNucPage, pixwidth);
3083         bfp->protViewControl = CreateViewControl (q, bfp, svpp, bfp->bioseqProtPageList,
3084                                                   bfp->currentProtPage, pixwidth);
3085       } else if (ISA_na (bsp->mol)) {
3086         bfp->nucViewControl = CreateViewControl (k, bfp, svpp, bfp->bioseqNucPageList,
3087                                                  bfp->currentNucPage, pixwidth);
3088       } else if (ISA_aa (bsp->mol)) {
3089         bfp->protViewControl = CreateViewControl (k, bfp, svpp, bfp->bioseqProtPageList,
3090                                                   bfp->currentProtPage, pixwidth);
3091       }
3092       if (bsp == NULL || ISA_na (bsp->mol)) {
3093         Hide (bfp->protViewControl);
3094       } else {
3095         Hide (bfp->nucViewControl);
3096       }
3097       if (bfp->nucViewControl != NULL) {
3098         ObjectRect (bfp->nucViewControl, &r);
3099         pixwidth = MAX (pixwidth, r.right - 2 * r.left - Nlm_vScrollBarWidth);
3100       } else if (bfp->protViewControl != NULL) {
3101         ObjectRect (bfp->protViewControl, &r);
3102         pixwidth = MAX (pixwidth, r.right - 2 * r.left - Nlm_vScrollBarWidth);
3103       }
3104       pixwidth = MAX (pixwidth, svpp->minPixelWidth);
3105       pixheight = MAX (pixheight, svpp->minPixelHeight);
3106       if (bfp->nucViewControl != NULL && Visible (bfp->nucViewControl)) {
3107         bfp->currentBioseqPage = bfp->bioseqNucPageList;
3108       } else if (bfp->protViewControl != NULL && Visible (bfp->protViewControl)) {
3109         bfp->currentBioseqPage = bfp->bioseqProtPageList;
3110       } else if (svpp != NULL) {
3111         bfp->currentBioseqPage = svpp->pageSpecs;
3112       }
3113     }
3114 
3115     if (svpp != NULL && svpp->useFolderTabs == CHANGE_VIEW_POPUP && k != NULL) {
3116       d = HiddenGroup (k, -2, 0, NULL);
3117       if (svpp->hasDuplicateButton) {
3118         dp = PushButton (d, "Duplicate", DuplicateViewProc);
3119         SetObjectExtra (dp, bfp, NULL);
3120       }
3121       h = HiddenGroup (d, 0, 0, NULL);
3122     } else {
3123       d = HiddenGroup (g, -2, 0, NULL);
3124       if (svpp != NULL && svpp->hasDuplicateButton) {
3125         dp = PushButton (d, "Duplicate", DuplicateViewProc);
3126         SetObjectExtra (dp, bfp, NULL);
3127       }
3128       h = HiddenGroup (d, 0, 0, NULL);
3129     }
3130 
3131     x = NULL;
3132     bfp->bvd.docTxtControlGrp = HiddenGroup (h, -4, 0, NULL);
3133     SetGroupSpacing (bfp->bvd.docTxtControlGrp, 3, 5);
3134     if (svpp != NULL && svpp->allowScrollText) {
3135       StaticPrompt (bfp->bvd.docTxtControlGrp, "Type", 0, popupMenuHeight, programFont, 'l');
3136       x = PopupList (bfp->bvd.docTxtControlGrp, TRUE, ChangeBioseqDocText);
3137       SetObjectExtra (x, bfp, NULL);
3138       PopupItem (x, "Doc");
3139       PopupItem (x, "Text");
3140     }
3141     bfp->bvd.modeControlGrp = HiddenGroup (bfp->bvd.docTxtControlGrp, -4, 0, NULL);
3142     StaticPrompt (bfp->bvd.modeControlGrp, "Mode", 0, popupMenuHeight, programFont, 'l');
3143     bfp->bvd.ffModeCtrl = PopupList (bfp->bvd.modeControlGrp, TRUE, ChangeFlatFileMode);
3144     SetObjectExtra (bfp->bvd.ffModeCtrl, bfp, NULL);
3145     PopupItem (bfp->bvd.ffModeCtrl, "Release");
3146     PopupItem (bfp->bvd.ffModeCtrl, "Entrez");
3147     PopupItem (bfp->bvd.ffModeCtrl, "Sequin");
3148     PopupItem (bfp->bvd.ffModeCtrl, "Dump");
3149     SetValue (bfp->bvd.ffModeCtrl, 3);
3150     bfp->bvd.baseCtgControlGrp = HiddenGroup (bfp->bvd.docTxtControlGrp, -3, 0, NULL);
3151     StaticPrompt (bfp->bvd.baseCtgControlGrp, "Style", 0, popupMenuHeight, programFont, 'l');
3152     bfp->bvd.ffStyleCtrl = PopupList (bfp->bvd.baseCtgControlGrp, TRUE, ChangeBioseqSequenceStyle);
3153     SetObjectExtra (bfp->bvd.ffStyleCtrl, bfp, NULL);
3154     PopupItem (bfp->bvd.ffStyleCtrl, "Normal");
3155     PopupItem (bfp->bvd.ffStyleCtrl, "Segment");
3156     PopupItem (bfp->bvd.ffStyleCtrl, "Master");
3157     PopupItem (bfp->bvd.ffStyleCtrl, "Contig");
3158     SetValue (bfp->bvd.ffStyleCtrl, 1);
3159     if (GetAppProperty ("InternalNcbiSequin") != NULL) {
3160       bfp->bvd.extraControlGrp = HiddenGroup (bfp->bvd.docTxtControlGrp, -6, 0, NULL);
3161       StaticPrompt (bfp->bvd.extraControlGrp, "Extra Quals", 0, popupMenuHeight, programFont, 'l');
3162       bfp->bvd.ffCustomBtn = PopupList (bfp->bvd.extraControlGrp, TRUE, ChangeFlatFileExtras);
3163       SetObjectExtra (bfp->bvd.ffCustomBtn, bfp, NULL);
3164       PopupItem (bfp->bvd.ffCustomBtn, "Off");
3165       PopupItem (bfp->bvd.ffCustomBtn, "On");
3166       SetValue (bfp->bvd.ffCustomBtn, 1);
3167       StaticPrompt (bfp->bvd.extraControlGrp, "Publications", 0, popupMenuHeight, programFont, 'l');
3168       bfp->bvd.ffRifCtrl = PopupList (bfp->bvd.extraControlGrp, TRUE, ChangeBioseqSequenceRIF);
3169       SetObjectExtra (bfp->bvd.ffRifCtrl, bfp, NULL);
3170       PopupItem (bfp->bvd.ffRifCtrl, "Show All");
3171       PopupItem (bfp->bvd.ffRifCtrl, "No GeneRIFs");
3172       PopupItem (bfp->bvd.ffRifCtrl, "Only GeneRIFs");
3173       PopupItem (bfp->bvd.ffRifCtrl, "Newest 5");
3174       PopupItem (bfp->bvd.ffRifCtrl, "Oldest 5");
3175       PopupItem (bfp->bvd.ffRifCtrl, "Only Reviews");
3176       PopupItem (bfp->bvd.ffRifCtrl, "Hide All");
3177       SetValue (bfp->bvd.ffRifCtrl, 1);
3178     }
3179     Hide (bfp->bvd.baseCtgControlGrp);
3180     Hide (bfp->bvd.docTxtControlGrp);
3181 
3182     s = HiddenGroup (h, -4, 0, NULL);
3183     bfp->bvd.styleControlGrp = HiddenGroup (s, -6, 0, NULL);
3184     StaticPrompt (bfp->bvd.styleControlGrp, "Style", 0, popupMenuHeight, programFont, 'l');
3185     bfp->bvd.style = PopupList (bfp->bvd.styleControlGrp, TRUE, ChangeStyle);
3186     SetObjectExtra (bfp->bvd.style, bfp, NULL);
3187     numStyles = GetMuskTotalSt ();
3188     for (i = 0; i < numStyles; i++) {
3189       styleName = GetMuskStyleName (i);
3190       if (StringCmp (styleName, "StyleX") != 0) {
3191         PopupItem (bfp->bvd.style, styleName);
3192       }
3193     }
3194     SetValue (bfp->bvd.style, GetMuskCurrentSt () + 1);
3195 
3196     y = HiddenGroup (s, 0, 0, NULL);
3197     bfp->bvd.scaleControlGrp = HiddenGroup (y, -6, 0, NULL);
3198     StaticPrompt (bfp->bvd.scaleControlGrp, "Scale", 0, popupMenuHeight, programFont, 'l');
3199     bfp->bvd.scale = PopupList (bfp->bvd.scaleControlGrp, TRUE, ChangeScale);
3200     SetObjectExtra (bfp->bvd.scale, bfp, NULL);
3201 
3202     bfp->bvd.findGeneGrp = HiddenGroup (y, -4, 0, NULL);
3203     z = PushButton (bfp->bvd.findGeneGrp, "Find by Gene or Product", ShowGeneList);
3204     SetObjectExtra (z, (Pointer) &(bfp->bvd), NULL);
3205 
3206     bfp->bvd.newGphControlGrp = HiddenGroup (h, -6, 0, NULL);
3207 
3208 #ifdef NEW_GRAPHICAL_VIEWER
3209     newGraphicalViewer = TRUE;
3210 #endif
3211     if (GetAppProperty ("NewSequinGraphicalViewer") != NULL) {
3212       newGraphicalViewer = TRUE;
3213     }
3214 
3215     if (newGraphicalViewer) {
3216       StaticPrompt (bfp->bvd.newGphControlGrp, "Style", 0, popupMenuHeight, programFont, 'l');
3217       bfp->bvd.newGphStyle = PopupList (bfp->bvd.newGphControlGrp, TRUE, ChangeNewStyle);
3218       SetObjectExtra (bfp->bvd.newGphStyle, bfp, NULL);
3219       PopupItems (bfp->bvd.newGphStyle, GetStyleNameList ());
3220       SetValue (bfp->bvd.newGphStyle, 1);
3221 
3222       StaticPrompt (bfp->bvd.newGphControlGrp, "Filter", 0, popupMenuHeight, programFont, 'l');
3223       bfp->bvd.newGphFilter = PopupList (bfp->bvd.newGphControlGrp, TRUE, ChangeNewFilter);
3224       SetObjectExtra (bfp->bvd.newGphFilter, bfp, NULL);
3225       PopupItems (bfp->bvd.newGphFilter, GetFilterNameList ());
3226       SetValue (bfp->bvd.newGphFilter, 1);
3227 
3228       /*
3229       if (GetAppProperty ("NewSequinLayoutOverride") != NULL) {
3230         newLayoutOverride = TRUE;
3231       }
3232       if (newLayoutOverride) {
3233         StaticPrompt (bfp->bvd.newGphControlGrp, "Layout", 0, popupMenuHeight, programFont, 'l');
3234         bfp->bvd.newGphLayout = PopupList (bfp->bvd.newGphControlGrp, TRUE, ChangeNewLayout);
3235         SetObjectExtra (bfp->bvd.newGphLayout, bfp, NULL);
3236         PopupItems (bfp->bvd.newGphLayout, GetLayoutNameList ());
3237         SetValue (bfp->bvd.newGphLayout, 1);
3238       }
3239       */
3240 
3241       StaticPrompt (bfp->bvd.newGphControlGrp, "Scale", 0, popupMenuHeight, programFont, 'l');
3242       bfp->bvd.newGphScale = PopupList (bfp->bvd.newGphControlGrp, TRUE, ChangeNewScale);
3243       SetObjectExtra (bfp->bvd.newGphScale, bfp, NULL);
3244 
3245       if (GetAppProperty("GPHVIEWSCOREALIGNS") != NULL) {
3246       /*
3247         StaticPrompt (bfp->bvd.newGphControlGrp, "Alignments: Score Type", 0, popupMenuHeight, programFont, 'l');
3248         bfp->bvd.newGphAlnScore = PopupList (bfp->bvd.newGphControlGrp, TRUE, ChangeNewFilter);
3249         SetObjectExtra (bfp->bvd.newGphAlnScore, bfp, NULL);
3250         PopupItems (bfp->bvd.newGphAlnScore, GetAlnScoreNameList ());
3251         SetValue (bfp->bvd.newGphAlnScore, 1);
3252       */
3253         StaticPrompt (bfp->bvd.newGphControlGrp, "Alignments: Score Cutoff", 0, popupMenuHeight, programFont, 'l');
3254         bfp->bvd.newGphAlnCutoff = PopupList (bfp->bvd.newGphControlGrp, TRUE, ChangeNewFilter);
3255         SetObjectExtra (bfp->bvd.newGphAlnCutoff, bfp, NULL);
3256         PopupItems (bfp->bvd.newGphAlnCutoff, GetAlnScoreCutoffList ());
3257         SetValue (bfp->bvd.newGphAlnCutoff, 1);
3258       }
3259     }
3260 
3261     Hide (bfp->bvd.styleControlGrp);
3262     Hide (bfp->bvd.scaleControlGrp);
3263     Hide (bfp->bvd.findGeneGrp);
3264     Hide (bfp->bvd.newGphControlGrp);
3265 
3266     if (b != NULL) {
3267       GetPosition (bfp->bvd.scale, &r2);
3268       GetPosition (b, &r1);
3269       delta = r2.left - r1.left;
3270       if (delta > 0) {
3271         OffsetRect (&r1, delta, 0);
3272         SetPosition (b, &r1);
3273         AdjustPrnt (b, &r1, FALSE);
3274         GetPosition (bfp->pubseq, &r1);
3275         OffsetRect (&r1, delta, 0);
3276         SetPosition (bfp->pubseq, &r1);
3277         AdjustPrnt (bfp->pubseq, &r1, FALSE);
3278       }
3279     } else {
3280       GetPosition (bfp->bvd.scale, &r2);
3281       GetPosition (bfp->pubseq, &r1);
3282       delta = r2.left - r1.left;
3283       if (delta > 0) {
3284         OffsetRect (&r1, delta, 0);
3285         SetPosition (bfp->pubseq, &r1);
3286         AdjustPrnt (bfp->pubseq, &r1, FALSE);
3287       }
3288     }
3289 
3290     if (bfp->bvd.launchEditors) {
3291       bfp->bvd.clickMe = StaticPrompt (g, "Double click on an item to launch the appropriate editor.",
3292                                        0, 0, programFont, 'l');
3293       if (bsp != NULL && bsp->hist != NULL && bsp->hist->replaced_by_ids != NULL) {
3294         SetTitle (bfp->bvd.clickMe, "This accession has been replaced by a newer record.");
3295       }
3296       Hide (bfp->bvd.clickMe);
3297     }
3298     else
3299     {
3300       bfp->bvd.clickMe = NULL;
3301     }
3302 
3303     h = HiddenGroup (g, 0, 0, NULL);
3304     SetGroupMargins (h, 1, 1);
3305 
3306     bfp->bvd.vwr = CreateViewer (h, pixwidth, pixheight, TRUE, TRUE);
3307     SetObjectExtra (bfp->bvd.vwr, (Pointer) &(bfp->bvd), NULL);
3308     bfp->bvd.pict = NULL;
3309     bfp->bvd.scaleNotCalculated = TRUE;
3310     bfp->bvd.moveToOldPos = FALSE;
3311     bfp->bvd.minIndex = 1;
3312     bfp->bvd.expansion = 1;
3313     Hide (bfp->bvd.vwr);
3314 
3315     fnt = programFont;
3316     if (bfp->bvd.displayFont != NULL) {
3317       fnt = bfp->bvd.displayFont;
3318     }
3319     bfp->bvd.text = ScrollText (h, pixwidth / stdCharWidth,
3320                                 pixheight / stdLineHeight, fnt, FALSE, NULL);
3321     SetObjectExtra (bfp->bvd.text, (Pointer) &(bfp->bvd), NULL);
3322     Hide (bfp->bvd.text);
3323 
3324     bfp->bvd.doc = DocumentPanel (h, pixwidth, pixheight);
3325     SetObjectExtra (bfp->bvd.doc, (Pointer) &(bfp->bvd), NULL);
3326     Hide (bfp->bvd.doc);
3327 
3328     bfp->bvd.pnlParentGrp = HiddenGroup (h, -1, 0, NULL);
3329     GetNextPosition (bfp->bvd.pnlParentGrp, &pt);
3330     pty = pt.y;
3331     pnlGrp = HiddenGroup (bfp->bvd.pnlParentGrp, 6, 0, NULL);
3332     StaticPrompt (pnlGrp, "Sequences", 0, popupMenuHeight, programFont, 'l');
3333     bfp->bvd.seqControl = PopupList (pnlGrp, TRUE, ChangeSalsaControls);
3334     SetObjectExtra (bfp->bvd.seqControl, bfp, NULL);
3335     PopupItem (bfp->bvd.seqControl, "Target");
3336     PopupItem (bfp->bvd.seqControl, "Aligned");
3337     SetValue (bfp->bvd.seqControl, 1);
3338     StaticPrompt (pnlGrp, "Features", 0, popupMenuHeight, programFont, 'l');
3339     bfp->bvd.featControl = PopupList (pnlGrp, TRUE, ChangeSalsaControls);
3340     SetObjectExtra (bfp->bvd.featControl, bfp, NULL);
3341     PopupItem (bfp->bvd.featControl, "None");
3342     PopupItem (bfp->bvd.featControl, "Target");
3343     PopupItem (bfp->bvd.featControl, "Aligned");
3344     SetValue (bfp->bvd.featControl, 2);
3345     StaticPrompt (pnlGrp, "Numbering", 0, popupMenuHeight, programFont, 'l');
3346     bfp->bvd.numControl = PopupList (pnlGrp, TRUE, ChangeSalsaControls);
3347     SetObjectExtra (bfp->bvd.numControl, bfp, NULL);
3348     PopupItem (bfp->bvd.numControl, "None");
3349     PopupItem (bfp->bvd.numControl, "Side");
3350     PopupItem (bfp->bvd.numControl, "Top");
3351     SetValue (bfp->bvd.numControl, 3);
3352     GetNextPosition (bfp->bvd.pnlParentGrp, &pt);
3353     bfp->bvd.pnl = SalsaTextPanel (bfp->bvd.pnlParentGrp, pixwidth, pixheight - (pt.y - pty));
3354     SetObjectExtra (bfp->bvd.pnl, (Pointer) &(bfp->bvd), NULL);
3355     Hide (bfp->bvd.pnl);
3356     Hide (bfp->bvd.pnlParentGrp);
3357 
3358     bfp->bvd.seqViewParentGrp = HiddenGroup (h, -1, 0, NULL);
3359     GetNextPosition (bfp->bvd.seqViewParentGrp, &pt);
3360     pty = pt.y;
3361     newPnlGrp = HiddenGroup (bfp->bvd.seqViewParentGrp, 8, 0, NULL);
3362     StaticPrompt (newPnlGrp, "Feature display: ", 0, popupMenuHeight, programFont, 'l');
3363     bfp->bvd.newFeatControl = PopupList (newPnlGrp, TRUE, ChangeSeqViewControls);
3364     SetObjectExtra (bfp->bvd.newFeatControl, bfp, NULL);
3365     PopupItem (bfp->bvd.newFeatControl, "-------");
3366     SetValue (bfp->bvd.newFeatControl, 1);
3367     StaticPrompt (newPnlGrp, " Numbering: ", 0, popupMenuHeight, programFont, 'l');
3368     bfp->bvd.newNumControl = PopupList (newPnlGrp, TRUE, ChangeSeqViewControls);
3369     SetObjectExtra (bfp->bvd.newNumControl, bfp, NULL);
3370     PopupItem (bfp->bvd.newNumControl, "None");
3371     PopupItem (bfp->bvd.newNumControl, "Side");
3372     PopupItem (bfp->bvd.newNumControl, "Top");
3373     SetValue (bfp->bvd.newNumControl, 3);
3374     StaticPrompt (newPnlGrp, " Grid: ", 0, popupMenuHeight, programFont, 'l');
3375     bfp->bvd.newGridControl = PopupList (newPnlGrp, TRUE, ChangeSeqViewControls);
3376     SetObjectExtra (bfp->bvd.newGridControl, bfp, NULL);
3377     PopupItem (bfp->bvd.newGridControl, "On");
3378     PopupItem (bfp->bvd.newGridControl, "Off");
3379     SetValue (bfp->bvd.newGridControl, 2);
3380 
3381     GetNextPosition (bfp->bvd.seqViewParentGrp, &pt);
3382     bfp->bvd.seqView = CreateSeqViewPanel (bfp->bvd.seqViewParentGrp, pixwidth, pixheight - (pt.y - pty));
3383     SetObjectExtra (bfp->bvd.seqView, bfp, NULL);
3384     Hide (bfp->bvd.seqView);
3385     Hide (bfp->bvd.seqViewParentGrp);
3386 
3387     /* for main Sequin view, always show substitutions in alignments */
3388     bfp->bvd.showAlnSubstitutions = TRUE;
3389 
3390     /* move PubMed button farther over */
3391     GetPosition (bfp->bvd.newGphScale, &r1);
3392     GetPosition (bfp->bvd.ffStyleCtrl, &r2);
3393     if (r1.right > r2.right) {
3394       GetPosition (bfp->bvd.newGphScale, &r2);
3395     }
3396     GetPosition (bfp->pubseq, &r1);
3397     delta = r2.right - r1.left + (r2.right - r2.left)/2;
3398     if (delta > 0) {
3399       OffsetRect (&r1, delta + 5, 0);
3400       SetPosition (bfp->pubseq, &r1);
3401       AdjustPrnt (bfp->pubseq, &r1, FALSE);
3402     }
3403     delta = r2.top - r1.top;
3404     if (delta > 0) {
3405       OffsetRect (&r1, 0, delta);
3406       SetPosition (bfp->pubseq, &r1);
3407       AdjustPrnt (bfp->pubseq, &r1, FALSE);
3408     }
3409 
3410     /*
3411     bfp->bvd.udvParentGrp = HiddenGroup (h, -1, 0, NULL);
3412     bfp->bvd.udv = AutonomousPanel4 (bfp->bvd.udvParentGrp, pixwidth, pixheight,
3413                                      UDV_draw_viewer, UnDViewerVScrlProc, NULL,
3414                                      sizeof (ViewerDialogDataPtr), UDVResetProc, NULL);
3415     SetObjectExtra (bfp->bvd.udvParentGrp, (Pointer) &(bfp->bvd), NULL);
3416     Hide (bfp->bvd.udvParentGrp);
3417 
3418     bfp->bvd.ddvParentGrp = HiddenGroup (h, -1, 0, NULL);
3419     bfp->bvd.ddv = AutonomousPanel4 (bfp->bvd.ddvParentGrp, pixwidth, pixheight,
3420                                      DDV_DrawViewer, DDV_VScrlProc, DDV_HScrlProc,
3421                                      sizeof (DdvMainPtr), DDVResetProc, NULL);
3422     SetObjectExtra (bfp->bvd.ddvParentGrp, (Pointer) &(bfp->bvd), NULL);
3423     Hide (bfp->bvd.ddvParentGrp);
3424     */
3425 
3426     if (makeControls != NULL) {
3427       if (bsp == NULL) {
3428         bfp->docuid = 0;
3429         bfp->doctype = TYP_NT;
3430         bfp->controls = makeControls (g, (BaseFormPtr) bfp, bfp->doctype, bfp->docuid);
3431       } else {
3432         bfp->docuid = GetUidFromBsp (bsp);
3433         if (bfp->docuid > 0) {
3434           if (ISA_na (bsp->mol)) {
3435             bfp->doctype = TYP_NT;
3436           } else if (ISA_aa (bsp->mol)) {
3437             bfp->doctype = TYP_AA;
3438           }
3439           bfp->controls = makeControls (g, (BaseFormPtr) bfp, bfp->doctype, bfp->docuid);
3440         } else if (makeAlignBtn != NULL) {
3441           bfp->retrieveAlignments = makeAlignBtn (g, (BaseFormPtr) bfp);
3442           if (bfp->retrieveAlignments != NULL && bfp->updateCounts != NULL) {
3443             entityID = ObjMgrGetEntityIDForPointer (bsp);
3444             sep = GetTopSeqEntryForEntityID (entityID);
3445             bfp->hasaligns = bfp->updateCounts (bfp->retrieveAlignments, sep);
3446           }
3447         }
3448       }
3449     }
3450 
3451     AlignObjects (ALIGN_CENTER, (HANDLE) bfp->bvd.text, (HANDLE) bfp->bvd.doc, NULL);
3452     AlignObjects (ALIGN_RIGHT, (HANDLE) bfp->bvd.vwr, (HANDLE)  bfp->bvd.text,
3453                   (HANDLE) bfp->bvd.doc, (HANDLE) bfp->bvd.pnl,
3454                   (HANDLE) bfp->bvd.clickMe, NULL);
3455     AlignObjects (ALIGN_LOWER, (HANDLE) bfp->bvd.vwr, (HANDLE)  bfp->bvd.text,
3456                   (HANDLE) bfp->bvd.doc, (HANDLE) bfp->bvd.pnl, NULL);
3457 
3458     GetPosition (bfp->bvd.vwr, &r3);
3459     AdjustPrnt (bfp->bvd.vwr, &r3, FALSE);
3460     GetPosition (bfp->bvd.text, &r3);
3461     AdjustPrnt (bfp->bvd.text, &r3, FALSE);
3462     GetPosition (bfp->bvd.doc, &r3);
3463     AdjustPrnt (bfp->bvd.doc, &r3, FALSE);
3464     GetPosition (bfp->bvd.pnl, &r3);
3465     AdjustPrnt (bfp->bvd.pnl, &r3, FALSE);
3466 
3467     if (bfp->bvd.useScrollText) {
3468       SetValue (x, 2);
3469     } else {
3470       SetValue (x, 1);
3471     }
3472 
3473     RealizeWindow (w);
3474 
3475     mssg = RegisterFormMenuItemName ("SequinLegendItem");
3476     bfp->bvd.legendItem = FindFormMenuItem ((BaseFormPtr) bfp, mssg);
3477     bfp->activate = NULL;
3478     if (svpp != NULL) {
3479       bfp->activate = svpp->activateForm;
3480     }
3481     SetActivate (w, BioseqViewFormActivate);
3482     Update ();
3483     BioseqViewFormActivate ((WindoW) bfp->form);
3484 
3485     /*
3486     if (svpp != NULL && svpp->lockFarComponents) {
3487       entityID = ObjMgrGetEntityIDForPointer (bsp);
3488       sep = GetTopSeqEntryForEntityID (entityID);
3489       bfp->bsplist = LockFarComponentsEx (sep, TRUE, FALSE, FALSE);
3490       LookupFarSeqIDs (sep, TRUE, TRUE, TRUE, TRUE);
3491     }
3492     */
3493 
3494     SendMessageToForm (bfp->form, VIB_MSG_INIT);
3495     SetCurrentPagePointers (bfp);
3496     if (bfp->input_entityID > 0 && bfp->bvd.hasTargetControl) {
3497       ChangeTarget ((Handle) bfp->targetControl); /* shows correct page and populates */
3498     } else {
3499       PointerToForm (bfp->form, bfp->bvd.bsp); /* shows correct page and populates */
3500     }
3501     Update ();
3502     AdjustDynamicGraphicViewer (&(bfp->bvd));
3503   }
3504   return (ForM) w;
3505 }
3506 
CreateNewSeqEntryViewForm(Int2 left,Int2 top,CharPtr title,BioseqPtr bsp,SeqViewProcsPtr svpp)3507 extern ForM LIBCALL CreateNewSeqEntryViewForm (Int2 left, Int2 top, CharPtr title,
3508                                                BioseqPtr bsp, SeqViewProcsPtr svpp)
3509 
3510 {
3511   return CreateNewSeqEntryViewFormEx (left, top, title, bsp, svpp, 0, 0, 0, FALSE);
3512 }
3513 
ShowFeatLegend(IteM i)3514 static void ShowFeatLegend (IteM i)
3515 
3516 {
3517   BioseqViewFormPtr  bfp;
3518   WindoW nw;
3519   SegmenT pic;
3520   Int2 style;
3521   CharPtr style_name;
3522   VieweR viewer;
3523   BoxInfo box_i;
3524   Int2 width, height;
3525 
3526 #ifdef WIN_MAC
3527   bfp = currentFormDataPtr;
3528 #else
3529   bfp = (BioseqViewFormPtr) GetObjectExtra (i);
3530 #endif
3531   if (bfp == NULL) return;
3532   if (bfp->bvd.ftype_list == NULL) return;
3533   style = GetValue (bfp->bvd.style) - 1;
3534   style_name = GetMuskStyleName (style);
3535 
3536   pic = pic_for_f_legend (bfp->bvd.ftype_list, style_name, 120);
3537   if (pic == NULL) return;
3538   SegmentBox (pic, &box_i);
3539   width = (box_i.right - box_i.left) + 20;
3540   height = (box_i.top - box_i.bottom) + 10;
3541   nw = FixedWindow (-50, -33, -10, -10, "Feature Legend", StdCloseWindowProc);
3542   viewer = CreateViewer (nw, width, height, FALSE, FALSE);
3543   AttachPicture (viewer, pic, 0, 0, UPPER_LEFT, 1, 1, NULL);
3544   Show (nw);
3545   Select (nw);
3546 }
3547 
CreateLegendItem(MenU m,BaseFormPtr bfp)3548 extern IteM CreateLegendItem (MenU m, BaseFormPtr bfp)
3549 
3550 {
3551   IteM  i;
3552   Int2  mssg;
3553 
3554   i = CommandItem (m, "Legend...", ShowFeatLegend);
3555   SetObjectExtra (i, bfp, NULL);
3556   mssg = RegisterFormMenuItemName ("SequinLegendItem");
3557   SetFormMenuItem (bfp, mssg, i);
3558   return i;
3559 }
3560 
EnableDisableLegendItem(BioseqViewPtr bvp,Boolean enable)3561 extern void EnableDisableLegendItem (BioseqViewPtr bvp, Boolean enable)
3562 
3563 {
3564   if (bvp == NULL) return;
3565   bvp->legendOK = enable;
3566   if (enable) {
3567     SafeEnable (bvp->legendItem);
3568   } else {
3569     SafeDisable (bvp->legendItem);
3570   }
3571 }
3572 
SetClickmeTitle(GatherContextPtr gcp)3573 static Boolean SetClickmeTitle (GatherContextPtr gcp)
3574 
3575 {
3576   BioseqViewFormPtr  bfp;
3577   Char               buf [80];
3578   DeltaSeqPtr        dsp;
3579   CharPtr            label = NULL;
3580   ObjMgrPtr          omp;
3581   ObjMgrTypePtr      omtp = NULL;
3582   Char               str [100];
3583 
3584   if (gcp == NULL || gcp->thisitem == NULL) {
3585     return FALSE;
3586   }
3587   bfp = (BioseqViewFormPtr) gcp->userdata;
3588   if (bfp == NULL) return FALSE;
3589   buf [0] = '\0';
3590   omp = ObjMgrGet ();
3591   if (omp != NULL) {
3592     omtp = ObjMgrTypeFind (omp, gcp->thistype, NULL, NULL);
3593     if (omtp != NULL && omtp->label != NULL) {
3594       label = omtp->label;
3595     }
3596     if (omtp != NULL && omtp->labelfunc != NULL) {
3597       (*(omtp->labelfunc)) (gcp->thisitem, buf, sizeof (buf) - 1, OM_LABEL_BOTH);
3598     } else if (gcp->thistype == OBJ_BIOSEQ_SEG) {
3599       SeqLocLabel (gcp->thisitem, buf, sizeof (buf) - 1, OM_LABEL_BOTH);
3600       label = "BioseqSeg";
3601     } else if (gcp->thistype == OBJ_BIOSEQ_DELTA) {
3602       dsp = (DeltaSeqPtr) gcp->thisitem;
3603       if (dsp != NULL && dsp->choice == 1) {
3604         SeqLocLabel ((SeqLocPtr) dsp->data.ptrvalue, buf, sizeof (buf) - 1, OM_LABEL_BOTH);
3605       }
3606       label = "BioseqDelta";
3607     }
3608   }
3609   if (! StringHasNoText (buf)) {
3610     str [0] = '\0';
3611     if (GetAppProperty ("InternalNcbiSequin") != NULL) {
3612       if (label == NULL) {
3613         label = "?";
3614       }
3615       sprintf (str, "%s %d - ", label, (int) gcp->itemID);
3616     }
3617     StringCat (str, buf);
3618     SafeSetTitle (bfp->bvd.clickMe, str);
3619     return TRUE;
3620   }
3621   /* SafeSetTitle (bfp->bvd.clickMe, "Double click on an item to launch the appropriate editor."); */
3622   SafeSetTitle (bfp->bvd.clickMe, "");
3623   return FALSE;
3624 }
3625 
InBioseqViewEntityList(Uint2 entityID,BioseqViewPtr bvp)3626 extern Boolean InBioseqViewEntityList (Uint2 entityID, BioseqViewPtr bvp)
3627 
3628 {
3629   ValNodePtr  vnp;
3630 
3631   if (entityID == 0 || bvp == NULL) return FALSE;
3632   for (vnp = bvp->entityList; vnp != NULL; vnp = vnp->next) {
3633     if (entityID == (Uint2) vnp->data.intvalue) {
3634       return TRUE;
3635     }
3636   }
3637   return FALSE;
3638 }
3639 
BioseqViewMsgFunc(OMMsgStructPtr ommsp)3640 extern Int2 LIBCALLBACK BioseqViewMsgFunc (OMMsgStructPtr ommsp)
3641 
3642 {
3643   BioseqViewFormPtr  bfp;
3644   BioseqPagePtr      bpp;
3645   BioseqPtr          bsp;
3646   Int2               count;
3647   Boolean            do_refresh;
3648   Uint2              itemtype;
3649   CharPtr            label = NULL;
3650   Boolean            last = FALSE;
3651   ObjMgrPtr          omp;
3652   ObjMgrDataPtr      omdp;
3653   ObjMgrTypePtr      omtp = NULL;
3654   OMUserDataPtr      omudp;
3655   Boolean            sametype;
3656   SelStructPtr       sel;
3657   SeqEntryPtr        sep;
3658   SeqLocPtr          slp;
3659   Char               str [100];
3660   SeqEntryPtr        top;
3661   Int2               val;
3662 
3663   omudp = (OMUserDataPtr)(ommsp->omuserdata);
3664   if (omudp == NULL) return OM_MSG_RET_ERROR;
3665   bfp = (BioseqViewFormPtr) omudp->userdata.ptrvalue;
3666   if (bfp == NULL) return OM_MSG_RET_ERROR;
3667   bsp = bfp->bvd.bsp;
3668   if (bsp == NULL) return OM_MSG_RET_ERROR;
3669   bpp = bfp->currentBioseqPage;
3670   if (bpp == NULL) return OM_MSG_RET_ERROR;
3671 
3672   if (ommsp->entityID != bfp->input_entityID) {
3673     if (! InBioseqViewEntityList (ommsp->entityID, &(bfp->bvd))) return OM_MSG_RET_OK;
3674   }
3675 
3676   do_refresh = FALSE;
3677   switch (ommsp->message) {
3678     case OM_MSG_DEL:
3679       if (ommsp->entityID == bfp->input_entityID) {
3680         do_refresh = TRUE;
3681         omdp = ObjMgrGetData (ommsp->entityID);
3682         if (omdp != NULL) {
3683           if (ObjMgrWholeEntity (omdp, ommsp->itemID, ommsp->itemtype)) {
3684             if (bfp != NULL) {
3685               RemoveSeqEntryViewer (bfp->form);
3686             }
3687             return OM_MSG_RET_OK;
3688           }
3689         }
3690       }
3691       break;
3692     case OM_MSG_CREATE:
3693       if (ommsp->entityID == bfp->input_entityID) {
3694         do_refresh = TRUE;
3695       }
3696       break;
3697     case OM_MSG_UPDATE:
3698       do_refresh = TRUE;
3699       break;
3700     case OM_MSG_SELECT:
3701       if (! bfp->bvd.highlightSelections) return OM_MSG_RET_OK;
3702       if (bpp->highlight == NULL) return OM_MSG_RET_OK;
3703       slp = NULL;
3704       if (ommsp->regiontype == OM_REGION_SEQLOC) {
3705         slp = (SeqLocPtr) ommsp->region;
3706       }
3707       bpp->highlight (&(bfp->bvd), ommsp->entityID, ommsp->itemID, ommsp->itemtype, slp, TRUE, TRUE);
3708       SendMessageToForm (bfp->form, VIB_MSG_SELECT);
3709       break;
3710     case OM_MSG_DESELECT:
3711       if (! bfp->bvd.highlightSelections) return OM_MSG_RET_OK;
3712       if (bpp->highlight == NULL) return OM_MSG_RET_OK;
3713       slp = NULL;
3714       if (ommsp->regiontype == OM_REGION_SEQLOC) {
3715         slp = (SeqLocPtr) ommsp->region;
3716       }
3717       bpp->highlight (&(bfp->bvd), ommsp->entityID, ommsp->itemID, ommsp->itemtype, slp, FALSE, FALSE);
3718       SendMessageToForm (bfp->form, VIB_MSG_SELECT);
3719       break;
3720     case OM_MSG_CACHED:
3721       break;
3722     case OM_MSG_UNCACHED:
3723       break;
3724     case OM_MSG_TO_CLIPBOARD:
3725       break;
3726     default :
3727       break;
3728   }
3729   if (do_refresh) {
3730     if (bfp->bvd.anp_node != NULL) {
3731       bfp->bvd.anp_node = FreeAlignNode (bfp->bvd.anp_node);
3732     }
3733     if (bfp->targetControl) {
3734       bfp->bvd.viewWholeEntity = FALSE;
3735       val = GetValue (bfp->targetControl);
3736       if (val == 1) {
3737         bfp->bvd.viewWholeEntity = TRUE;
3738       } else {
3739         val--;
3740       }
3741       top = GetTopSeqEntryForEntityID (bfp->input_entityID);
3742       if (top != NULL) {
3743         sep = FindNthSequinEntry (top, val);
3744         /* check to see if user just deleted the last target */
3745         while (sep == NULL && val > 1) {
3746           last = TRUE;
3747           val--;
3748           sep = FindNthSequinEntry (top, val);
3749         }
3750         if (sep != NULL && sep->choice == 1 && sep->data.ptrvalue != NULL) {
3751           bsp = (BioseqPtr) sep->data.ptrvalue;
3752           /*
3753           bfp->scaleNotCalculated = TRUE;
3754           */
3755           bfp->bvd.moveToOldPos = TRUE;
3756           /*
3757           if (bfp->bvd.bsp != bsp) {
3758             BioseqLock (bsp);
3759             BioseqUnlock (bfp->bvd.bsp);
3760           }
3761           */
3762           bfp->bvd.bsp = bsp;
3763           if (last) {
3764             if (! bfp->bvd.viewWholeEntity) {
3765               val++;
3766             }
3767             SetValue (bfp->targetControl, val);
3768           }
3769         } else {
3770           bfp->bvd.bsp = NULL;
3771         }
3772       }
3773     }
3774     PointerToForm (bfp->form, (Pointer) bfp->bvd.bsp);
3775     AdjustDynamicGraphicViewer (&(bfp->bvd));
3776 
3777     UpdateSeqViewPanel (bfp->bvd.seqView);
3778   }
3779   if (ommsp->message == OM_MSG_SELECT || ommsp->message == OM_MSG_DESELECT) {
3780     ResetClip ();
3781     sel = ObjMgrGetSelected ();
3782     if (sel != NULL && sel->next == NULL &&
3783         (sel->entityID == bfp->input_entityID || InBioseqViewEntityList (sel->entityID, &(bfp->bvd)))) {
3784       GatherItem (sel->entityID, sel->itemID, sel->itemtype, (Pointer) bfp, SetClickmeTitle);
3785     } else if (sel != NULL && sel->next != NULL) {
3786       count = 0;
3787       sametype = TRUE;
3788       itemtype = sel->itemtype;
3789       while (sel != NULL) {
3790         if (sel->itemtype != itemtype) {
3791           sametype = FALSE;
3792         }
3793         count++;
3794         sel = sel->next;
3795       }
3796       sprintf (str, "%d items selected", (int) count);
3797       if (sametype) {
3798         omp = ObjMgrGet ();
3799         if (omp != NULL) {
3800           omtp = ObjMgrTypeFind (omp, itemtype, NULL, NULL);
3801           if (omtp != NULL && omtp->label != NULL) {
3802             label = omtp->label;
3803             if (label != NULL) {
3804               sprintf (str, "%d %s items selected", (int) count, label);
3805             }
3806           }
3807         }
3808       }
3809       SafeSetTitle (bfp->bvd.clickMe, str);
3810     } else {
3811       /* SafeSetTitle (bfp->bvd.clickMe, "Double click on an item to launch the appropriate editor."); */
3812       SafeSetTitle (bfp->bvd.clickMe, "");
3813     }
3814     if (ommsp->message == OM_MSG_SELECT) {
3815       Update ();
3816     }
3817   }
3818   return OM_MSG_RET_OK;
3819 }
3820 
SaveToolBarPos(WindoW w)3821 static void SaveToolBarPos (WindoW w)
3822 {
3823   RecT r;
3824   Char str [256];
3825   if (w == NULL)
3826   {
3827     return;
3828   }
3829 
3830   GetPosition (w, &r);
3831 
3832   sprintf (str, "%d", r.left);
3833   SetAppParam ("SEQUINCUSTOM", "PREFERENCES", "TOOLBARLEFT", str);
3834   sprintf (str, "%d", r.top);
3835   SetAppParam ("SEQUINCUSTOM", "PREFERENCES", "TOOLBARTOP", str);
3836 }
3837 
CleanSmartViewer(BioseqViewFormPtr bfp)3838 static void CleanSmartViewer (BioseqViewFormPtr bfp)
3839 
3840 {
3841   BioseqPagePtr  bpp;
3842   Uint2          userkey;
3843   ValNodePtr     vnp;
3844 
3845   if (bfp == NULL) return;
3846   bpp = bfp->currentBioseqPage;
3847   if (bpp != NULL && bpp->show != NULL) {
3848     bpp->show (&(bfp->bvd), FALSE);
3849     Update ();
3850   }
3851   if (bfp->input_entityID > 0) {
3852     if (bfp->userkey > 0) {
3853       userkey = bfp->userkey;
3854       bfp->userkey = 0;
3855       ObjMgrFreeUserData (bfp->input_entityID, bfp->procid, bfp->proctype, userkey);
3856       /* this may trigger another remove, hence bfp->userkey first set to 0 */
3857       for (vnp = bfp->bvd.entityList; vnp != NULL; vnp = vnp->next) {
3858         if (bfp->input_entityID != (Uint2) vnp->data.intvalue) {
3859           ObjMgrFreeUserData ((Uint2) vnp->data.intvalue, bfp->procid, bfp->proctype, userkey);
3860         }
3861       }
3862     }
3863     bfp->bvd.bsplist = UnlockFarComponents (bfp->bvd.bsplist);
3864     bfp->bvd.pict = DeletePicture (bfp->bvd.pict);
3865     if (bfp->bvd.slp_list != NULL) {
3866       bfp->bvd.slp_list = free_slp_list (bfp->bvd.slp_list);
3867     }
3868     if (bfp->bvd.anp_node != NULL) {
3869       bfp->bvd.anp_node = FreeAlignNode (bfp->bvd.anp_node);
3870     }
3871     if (bfp->bvd.g_list != NULL) {
3872       bfp->bvd.g_list = ValNodeFreeData (bfp->bvd.g_list);
3873     }
3874     if (bfp->bvd.ftype_list != NULL) {
3875       bfp->bvd.ftype_list = ValNodeFree (bfp->bvd.ftype_list);
3876     }
3877     if (bfp->bvd.sentinelList != NULL) {
3878       bfp->bvd.sentinelList = ValNodeFreeData (bfp->bvd.sentinelList);
3879     }
3880     if (bfp->bvd.entityList != NULL) {
3881       bfp->bvd.entityList = ValNodeFree (bfp->bvd.entityList);
3882     }
3883   }
3884   if (bfp->toolForm != NULL) {
3885     /* Hide (bfp->toolForm); */
3886     SaveToolBarPos ((WindoW)bfp->toolForm);
3887     bfp->toolForm = Remove (bfp->toolForm);
3888   }
3889 }
3890 
ToolFormHideWindowProc(WindoW w)3891 static void ToolFormHideWindowProc (WindoW w)
3892 
3893 {
3894   SaveToolBarPos (w);
3895   Hide (w);
3896 }
3897 
GetToolBarRect(Int2Ptr left,Int2Ptr top)3898 static void GetToolBarRect (Int2Ptr left, Int2Ptr top)
3899 {
3900   Char        str [256];
3901   Int2        val;
3902 
3903   if (left != NULL)
3904   {
3905     if (GetAppParam ("SEQUINCUSTOM", "PREFERENCES", "TOOLBARLEFT", NULL, str, sizeof (str))
3906         && StrToInt (str, &val) && val > 0)
3907     {
3908       *left = val;
3909     }
3910     else
3911     {
3912       *left = -5;
3913     }
3914   }
3915 
3916   if (top != NULL)
3917   {
3918     if (GetAppParam ("SEQUINCUSTOM", "PREFERENCES", "TOOLBARTOP", NULL, str, sizeof (str))
3919         && StrToInt (str, &val) && val > 0)
3920     {
3921       *top = val;
3922     }
3923     else
3924     {
3925       *top = -50;
3926     }
3927   }
3928 
3929 }
3930 
MakeToolFormForBioseqView(BaseFormPtr bafp,GrpActnProc createToolBar)3931 extern ForM MakeToolFormForBioseqView (BaseFormPtr bafp, GrpActnProc createToolBar)
3932 
3933 {
3934   BioseqViewFormPtr  bfp;
3935   GrouP              g;
3936   CharPtr            ptr;
3937   Char               str [512];
3938   WindoW             w;
3939   Int2               left, top;
3940 
3941   bfp = (BioseqViewFormPtr) bafp;
3942   if (bfp == NULL || createToolBar == NULL) return NULL;
3943   if (bfp->toolForm != NULL) return bfp->toolForm;
3944 
3945   GetTitle (bfp->form, str, sizeof (str));
3946   TrimSpacesAroundString (str);
3947   ptr = StringStr (str, " - ");
3948   if (ptr != NULL) {
3949     *ptr = '\0';
3950   }
3951   if (StringHasNoText (str)) {
3952     StringCpy (str, "ToolBar");
3953   } else {
3954     StringCat (str, " -- ToolBar");
3955   }
3956 
3957   GetToolBarRect (&left, &top);
3958   w = FixedWindow (left, top, -10, -10, str, ToolFormHideWindowProc);
3959   if (w == NULL) return NULL;
3960   g = HiddenGroup (w, -1, 0, NULL);
3961   SetObjectExtra (g, bfp, NULL);
3962   createToolBar (g);
3963   RealizeWindow (w);
3964   bfp->toolForm = (ForM) w;
3965   return (ForM) w;
3966 }
3967 
ReplaceToolFormForBioseqView(BaseFormPtr bafp,GrpActnProc createToolBar)3968 extern ForM ReplaceToolFormForBioseqView (BaseFormPtr bafp, GrpActnProc createToolBar)
3969 
3970 {
3971   BioseqViewFormPtr  bfp;
3972   GrouP              g;
3973   CharPtr            ptr;
3974   Char               str [512];
3975   WindoW             w;
3976   Int2               left, top;
3977 
3978   bfp = (BioseqViewFormPtr) bafp;
3979   if (bfp == NULL || createToolBar == NULL) return NULL;
3980   if (bfp->toolForm != NULL) {
3981     bfp->toolForm = Remove (bfp->toolForm);
3982   }
3983 
3984   GetTitle (bfp->form, str, sizeof (str));
3985   TrimSpacesAroundString (str);
3986   ptr = StringStr (str, " - ");
3987   if (ptr != NULL) {
3988     *ptr = '\0';
3989   }
3990   if (StringHasNoText (str)) {
3991     StringCpy (str, "ToolBar");
3992   } else {
3993     StringCat (str, " -- ToolBar");
3994   }
3995 
3996   GetToolBarRect (&left, &top);
3997   w = FixedWindow (left, top, -10, -10, str, ToolFormHideWindowProc);
3998   if (w == NULL) return NULL;
3999   g = HiddenGroup (w, -1, 0, NULL);
4000   SetObjectExtra (g, bfp, NULL);
4001   createToolBar (g);
4002   RealizeWindow (w);
4003   bfp->toolForm = (ForM) w;
4004   return (ForM) w;
4005 }
4006 
ReplaceToolFormWithDataForBioseqView(BaseFormPtr bafp,BuildToolbarProc createToolBar,Pointer data)4007 extern ForM ReplaceToolFormWithDataForBioseqView (BaseFormPtr bafp, BuildToolbarProc createToolBar, Pointer data)
4008 
4009 {
4010   BioseqViewFormPtr  bfp;
4011   GrouP              g;
4012   CharPtr            ptr;
4013   Char               str [512];
4014   WindoW             w;
4015   Int2               left, top;
4016 
4017   bfp = (BioseqViewFormPtr) bafp;
4018   if (bfp == NULL || createToolBar == NULL) return NULL;
4019   if (bfp->toolForm != NULL) {
4020     bfp->toolForm = Remove (bfp->toolForm);
4021   }
4022 
4023   GetTitle (bfp->form, str, sizeof (str));
4024   TrimSpacesAroundString (str);
4025   ptr = StringStr (str, " - ");
4026   if (ptr != NULL) {
4027     *ptr = '\0';
4028   }
4029   if (StringHasNoText (str)) {
4030     StringCpy (str, "ToolBar");
4031   } else {
4032     StringCat (str, " -- ToolBar");
4033   }
4034 
4035   GetToolBarRect (&left, &top);
4036   w = FixedWindow (left, top, -10, -10, str, ToolFormHideWindowProc);
4037   if (w == NULL) return NULL;
4038   g = HiddenGroup (w, -1, 0, NULL);
4039   SetObjectExtra (g, bfp, NULL);
4040   createToolBar (g, data);
4041   RealizeWindow (w);
4042   bfp->toolForm = (ForM) w;
4043   return (ForM) w;
4044 }
4045 
RemoveSeqEntryViewer(ForM f)4046 extern ForM RemoveSeqEntryViewer (ForM f)
4047 
4048 {
4049   BioseqViewFormPtr  bfp;
4050   SeqViewProcsPtr    svpp;
4051 
4052   bfp = (BioseqViewFormPtr) GetObjectExtra (f);
4053   if (f == smartBioseqViewForm) {
4054     svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
4055     if (svpp != NULL && (! svpp->keepSmartViewerVisible)) {
4056       Hide (f);
4057       if (bfp != NULL) {
4058         SaveToolBarPos ((WindoW)bfp->toolForm);
4059         bfp->toolForm = Remove (bfp->toolForm);
4060       }
4061     }
4062     CleanSmartViewer (bfp);
4063   } else {
4064     if (bfp != NULL) {
4065       SaveToolBarPos ((WindoW)bfp->toolForm);
4066       bfp->toolForm = Remove (bfp->toolForm);
4067     }
4068     Remove (f);
4069   }
4070   return NULL;
4071 }
4072 
NewSeqEntryViewGenFunc(Pointer data)4073 extern Int2 LIBCALLBACK NewSeqEntryViewGenFunc (Pointer data)
4074 
4075 {
4076   BioseqContextPtr   bcp;
4077   BioseqViewFormPtr  bfp;
4078   BioseqPtr          bsp;
4079   ForM               f;
4080   OMProcControlPtr   ompcp;
4081   OMUserDataPtr      omudp;
4082   ValNodePtr         sdp;
4083   SeqEntryPtr        sep;
4084   SeqIdPtr           sip;
4085   Char               str [PATH_MAX];
4086   SeqViewProcsPtr    svpp;
4087   CharPtr            timestamptitle;
4088   ValNodePtr         ttl;
4089   WindoW             w;
4090 
4091   ompcp = (OMProcControlPtr) data;
4092   bsp = NULL;
4093   if (ompcp == NULL || ompcp->proc == NULL) return OM_MSG_RET_ERROR;
4094   switch (ompcp->input_itemtype) {
4095     case OBJ_BIOSEQ :
4096       bsp = (BioseqPtr) ompcp->input_data;
4097       break;
4098     case OBJ_BIOSEQSET :
4099       return OM_MSG_RET_ERROR;
4100     case 0 :
4101       return OM_MSG_RET_ERROR;
4102     default :
4103       return OM_MSG_RET_ERROR;
4104   }
4105   if (bsp == NULL) return OM_MSG_RET_ERROR;
4106   sip = SeqIdFindWorst (bsp->id);
4107   if (sip == NULL) return OM_MSG_RET_ERROR;
4108   SeqIdWrite (sip, str, PRINTID_REPORT, sizeof (str));
4109   sep = GetTopSeqEntryForEntityID (ompcp->input_entityID);
4110   if (sep != NULL && IsAGenomeRecord (sep)) {
4111     bcp = BioseqContextNew (bsp);
4112     ttl = NULL;
4113     sdp = BioseqContextGetSeqDescr (bcp, Seq_descr_title, NULL, NULL);
4114     while (sdp != NULL) {
4115       ttl = sdp;
4116       sdp = BioseqContextGetSeqDescr (bcp, Seq_descr_title, sdp, NULL);
4117     }
4118     BioseqContextFree (bcp);
4119     if (ttl != NULL && (! StringHasNoText ((CharPtr) ttl->data.ptrvalue))) {
4120       StringNCpy_0 (str, (CharPtr) ttl->data.ptrvalue, sizeof (str));
4121     }
4122   }
4123   /* append timestamp to title */
4124   timestamptitle = GetAppProperty ("SmartSequinTimeStampTitle");
4125   if (timestamptitle != NULL) {
4126     StringCat (str, " ");
4127     StringCat (str, timestamptitle);
4128   }
4129   w = (WindoW) CreateNewSeqEntryViewFormEx (-50, -33, str, bsp, NULL, ompcp->input_entityID,
4130                                             ompcp->input_itemID, ompcp->input_itemtype, FALSE);
4131   bfp = (BioseqViewFormPtr) GetObjectExtra (w);
4132   if (bfp != NULL) {
4133     bfp->input_entityID = ompcp->input_entityID;
4134     bfp->input_itemID = ompcp->input_itemID;
4135     bfp->input_itemtype = ompcp->input_itemtype;
4136     bfp->this_itemtype = OBJ_BIOSEQ;
4137     bfp->this_subtype = bsp->repr;
4138     bfp->procid = ompcp->proc->procid;
4139     bfp->proctype = ompcp->proc->proctype;
4140     bfp->docuid = GetUidFromBsp (bsp);
4141     if (ISA_na (bsp->mol)) {
4142       bfp->doctype = TYP_NT;
4143     } else if (ISA_aa (bsp->mol)) {
4144       bfp->doctype = TYP_AA;
4145     }
4146     bfp->userkey = OMGetNextUserKey ();
4147     omudp = ObjMgrAddUserData (ompcp->input_entityID, ompcp->proc->procid,
4148                                ompcp->proc->proctype, bfp->userkey);
4149     if (omudp != NULL) {
4150       omudp->userdata.ptrvalue = (Pointer) bfp;
4151       omudp->messagefunc = BioseqViewMsgFunc;
4152     }
4153     SendMessageToForm (bfp->form, VIB_MSG_CHANGE);
4154   }
4155   Show (w);
4156   if (bfp != NULL) {
4157     svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
4158     if (svpp != NULL && svpp->createToolBar != NULL) {
4159       f = MakeToolFormForBioseqView ((BaseFormPtr) bfp, svpp->createToolBar);
4160       Show (f);
4161     }
4162   }
4163   Select (w);
4164   return OM_MSG_RET_DONE;
4165 }
4166 
4167 
HasAccessionCallback(BioseqPtr bsp,Pointer data)4168 static void HasAccessionCallback (BioseqPtr bsp, Pointer data)
4169 {
4170   BoolPtr p_rval;
4171   SeqIdPtr sip;
4172   Boolean found = FALSE;
4173 
4174   if (bsp == NULL
4175       || (p_rval = (BoolPtr) data) == NULL
4176       || !(*p_rval)
4177       || ISA_aa (bsp->mol)) {
4178     return;
4179   }
4180 
4181   for (sip = bsp->id; sip != NULL && !found; sip = sip->next) {
4182     if (sip->choice == SEQID_GENBANK) {
4183       found = TRUE;
4184     }
4185   }
4186   *p_rval = found;
4187 }
4188 
4189 
HasGICallback(BioseqPtr bsp,Pointer data)4190 static void HasGICallback (BioseqPtr bsp, Pointer data)
4191 {
4192   BoolPtr p_rval;
4193   SeqIdPtr sip;
4194   Boolean found = FALSE;
4195 
4196   if (bsp == NULL
4197       || (p_rval = (BoolPtr) data) == NULL
4198       || (*p_rval)
4199       || ISA_aa (bsp->mol)) {
4200     return;
4201   }
4202 
4203   for (sip = bsp->id; sip != NULL && !found; sip = sip->next) {
4204     if (sip->choice == SEQID_GI) {
4205       found = TRUE;
4206     }
4207   }
4208   *p_rval = found;
4209 }
4210 
4211 
AllSequencesHaveAccessionsButNoGis(SeqEntryPtr sep)4212 static Boolean AllSequencesHaveAccessionsButNoGis (SeqEntryPtr sep)
4213 {
4214   Boolean rval = FALSE;
4215   Boolean has_accession = TRUE;
4216   Boolean has_gi = FALSE;
4217   VisitBioseqsInSep (sep, &has_accession, HasAccessionCallback);
4218   if (has_accession) {
4219     VisitBioseqsInSep (sep, &has_gi, HasGICallback);
4220     if (!has_gi) {
4221       rval = TRUE;
4222     }
4223   }
4224 
4225   return rval;
4226 }
4227 
4228 
IsPrefixPlusOptionalDigits(CharPtr str,CharPtr prefix)4229 static Boolean IsPrefixPlusOptionalDigits (CharPtr str, CharPtr prefix)
4230 {
4231   Int4 len = StringLen (prefix);
4232 
4233   if (StringNICmp (str, prefix, len) == 0
4234       && (StringHasNoText (str + len) || StringIsAllDigits (str + len))) {
4235     return TRUE;
4236   } else {
4237     return FALSE;
4238   }
4239 }
4240 
4241 
IsFixableIDString(CharPtr str)4242 static Boolean IsFixableIDString (CharPtr str)
4243 {
4244   if (StringHasNoText (str)) {
4245     return FALSE;
4246   } else if (IsPrefixPlusOptionalDigits (str, "SeqID")) {
4247     return TRUE;
4248   } else if (IsPrefixPlusOptionalDigits (str, "Seq")) {
4249     return TRUE;
4250   } else if (IsPrefixPlusOptionalDigits (str, "Sequence")) {
4251     return TRUE;
4252   } else {
4253     return FALSE;
4254   }
4255 }
4256 
4257 
HasConflictingFixableLocalIdsCallback(BioseqPtr bsp,Pointer data)4258 static void HasConflictingFixableLocalIdsCallback (BioseqPtr bsp, Pointer data)
4259 {
4260   BoolPtr p_rval;
4261   SeqIdPtr sip1;
4262   BioseqPtr bsp2;
4263   ObjectIdPtr oip;
4264 
4265   if (bsp == NULL || (p_rval = (BoolPtr) data) == NULL || *p_rval) {
4266     return;
4267   }
4268 
4269   for (sip1 = bsp->id; sip1 != NULL; sip1 = sip1->next) {
4270     if (sip1->choice == SEQID_LOCAL
4271         && (oip = (ObjectIdPtr) sip1->data.ptrvalue) != NULL
4272         && IsFixableIDString(oip->str)) {
4273       bsp2 = BioseqFindSpecial (sip1);
4274       if (bsp2 != NULL && bsp2 != bsp) {
4275         *p_rval = TRUE;
4276       }
4277     }
4278   }
4279 }
4280 
4281 
HasConflictingFixableLocalIds(SeqEntryPtr sep)4282 static Boolean HasConflictingFixableLocalIds (SeqEntryPtr sep)
4283 {
4284   Boolean rval = FALSE;
4285 
4286   VisitBioseqsInSep (sep, &rval, HasConflictingFixableLocalIdsCallback);
4287   return rval;
4288 }
4289 
4290 
4291 
HasConflictingIDsCallback(BioseqPtr bsp,Pointer data)4292 static void HasConflictingIDsCallback (BioseqPtr bsp, Pointer data)
4293 {
4294   BoolPtr p_rval;
4295   SeqIdPtr sip1;
4296   BioseqPtr bsp2;
4297   DbtagPtr  dbt;
4298 
4299   if (bsp == NULL || (p_rval = (BoolPtr) data) == NULL || *p_rval) {
4300     return;
4301   }
4302 
4303   for (sip1 = bsp->id; sip1 != NULL; sip1 = sip1->next) {
4304     bsp2 = BioseqFindSpecial (sip1);
4305     if (bsp2 != NULL && bsp2 != bsp) {
4306       if (sip1->choice == SEQID_GENERAL
4307           && (dbt = (DbtagPtr) sip1->data.ptrvalue) != NULL
4308           && StringICmp (dbt->db, "NCBIFILE") == 0) {
4309         continue;
4310       }
4311       *p_rval = TRUE;
4312     }
4313   }
4314 }
4315 
4316 
HasConflictingIds(SeqEntryPtr sep)4317 static Boolean HasConflictingIds (SeqEntryPtr sep)
4318 {
4319   Boolean rval = FALSE;
4320 
4321   VisitBioseqsInSep (sep, &rval, HasConflictingIDsCallback);
4322   return rval;
4323 }
4324 
4325 
4326 static WindoW sAutofixReportWindow = NULL;
4327 
CloseReportWindowProc(WindoW w)4328 static void CloseReportWindowProc (WindoW w)
4329 
4330 {
4331   sAutofixReportWindow = NULL;
4332   Remove (w);
4333 }
4334 
MakeAutofixReportWindow(LogInfoPtr lip)4335 static void MakeAutofixReportWindow (LogInfoPtr lip)
4336 {
4337   GrouP h;
4338   DoC   doc;
4339   ReadBufferData rbd;
4340   CharPtr line;
4341 
4342   if (sAutofixReportWindow == NULL) {
4343     if (lip == NULL || StringHasNoText (lip->path) || !lip->data_in_log) {
4344       return;
4345     }
4346     sAutofixReportWindow = FixedWindow (-50, -33, -10, -10, "Autofix Report", CloseReportWindowProc);
4347     h = HiddenGroup (sAutofixReportWindow, -1, 0, NULL);
4348     SetGroupSpacing (h, 10, 10);
4349     doc = DocumentPanel (h, stdCharWidth * 50, stdLineHeight * 24);
4350     SetObjectExtra (sAutofixReportWindow, doc, NULL);
4351     RealizeWindow (sAutofixReportWindow);
4352   }
4353   doc = (DoC) GetObjectExtra (sAutofixReportWindow);
4354   Reset (doc);
4355   if (lip != NULL && !StringHasNoText (lip->path) && lip->data_in_log) {
4356     FileClose (lip->fp);
4357     lip->fp = NULL;
4358     rbd.fp = FileOpen (lip->path, "r");
4359     if (rbd.fp != NULL) {
4360       rbd.current_data = NULL;
4361       line = AbstractReadFunction (&rbd);
4362       while (line != NULL)
4363       {
4364         AppendText (doc, line, NULL, NULL, systemFont);
4365         line = MemFree (line);
4366         line = AbstractReadFunction (&rbd);
4367       }
4368       FileClose (rbd.fp);
4369     }
4370   }
4371 
4372   /* redraw */
4373   InvalDocument (doc);
4374   Show (sAutofixReportWindow);
4375   Select (sAutofixReportWindow);
4376   Update();
4377 }
4378 
4379 
RunAutoFixScript(BaseFormPtr bfp,Boolean add_object,Nlm_ChangeNotifyProc change_notify,Pointer change_data)4380 NLM_EXTERN void RunAutoFixScript (BaseFormPtr bfp, Boolean add_object, Nlm_ChangeNotifyProc change_notify, Pointer change_data)
4381 {
4382   AsnIoPtr     aip;
4383   Char         buf [PATH_MAX];
4384   ValNodePtr   action_list;
4385   SeqEntryPtr  sep;
4386   Uint2        entityID;
4387   LogInfoPtr   lip;
4388   LclIdListPtr head = NULL;
4389 
4390   if (bfp == NULL) return;
4391 
4392   sep = GetTopSeqEntryForEntityID(bfp->input_entityID);
4393   if (sep == NULL) {
4394     return;
4395   }
4396 
4397   if (add_object && !AllSequencesHaveAccessionsButNoGis(sep)) {
4398     return;
4399   }
4400 
4401   /* need to fix colliding local IDs, if possible */
4402   if (HasConflictingFixableLocalIds(sep)) {
4403     if (HasAlignmentsWithLocalIDs (sep))
4404     {
4405       if (ANS_CANCEL == Message (MSG_OKC, "This record contains colliding local IDs, and has alignments with local IDs.  You will need to repair the alignments manually if you resolve colliding IDs.  Do you want to continue (and run Autofix)?"))
4406       {
4407         return;
4408       }
4409     }
4410     SeqEntryExplore (sep, (Pointer) &head, ResolveExistingIDsCallback);
4411     FreeLclTree (&head);
4412     ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
4413     ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
4414   }
4415 
4416   if (HasConflictingIds(sep)) {
4417     Message (MSG_ERROR, "Can't run autofix - there are colliding local IDs.");
4418     return;
4419   }
4420 
4421   if (! FindPath("ncbi", "ncbi", "data", buf, sizeof (buf)))
4422   {
4423     Message (MSG_ERROR, "Failed to find Auto-fix script");
4424     return;
4425   }
4426 
4427   StringCat(buf, "autofix.prt");
4428 
4429   aip = AsnIoOpen (buf, "r");
4430   if (aip == NULL) {
4431     Message (MSG_ERROR, "Unable to open %s", buf);
4432     return;
4433   }
4434 
4435   action_list = MacroActionListAsnRead (aip, NULL);
4436   AsnIoClose (aip);
4437 
4438   if (action_list == NULL) {
4439     Message (MSG_ERROR, "Unable to read action list from %s.", buf);
4440     return;
4441   }
4442 
4443   WatchCursor();
4444   Update();
4445   lip = OpenLog ("AutoFix Actions");
4446   entityID = ObjMgrGetEntityIDForChoice(sep);
4447   lip->data_in_log |= ApplyMacroToSeqEntryEx (sep, action_list, lip->fp, Sequin_GlobalAlign2Seq);
4448   if (add_object) {
4449     AddNcbiAutofixUserObject(sep);
4450   }
4451   if (change_notify != NULL) {
4452     change_notify (change_data);
4453   }
4454   ObjMgrSetDirtyFlag (entityID, TRUE);
4455   ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
4456   /*CloseLog(lip); */
4457   MakeAutofixReportWindow (lip);
4458   lip = FreeLog(lip);
4459   ArrowCursor ();
4460   Update ();
4461 }
4462 
4463 
AutofixOnStartup(BaseFormPtr bfp,Nlm_ChangeNotifyProc change_notify,Pointer change_data)4464 NLM_EXTERN void AutofixOnStartup (BaseFormPtr bfp, Nlm_ChangeNotifyProc change_notify, Pointer change_data)
4465 {
4466   Char        str [256];
4467   SeqEntryPtr sep;
4468 
4469   CacheAppParam (FALSE);
4470   if (GetAppParam ("SEQUINCUSTOM", "SETTINGS", "AUTOFIX", NULL, str, sizeof (str))) {
4471     if (StringICmp (str, "TRUE") == 0) {
4472       sep = GetTopSeqEntryForEntityID (bfp->input_entityID);
4473       if (FindNcbiAutofixUserObject(sep) == NULL) {
4474         RunAutoFixScript (bfp, TRUE, change_notify, change_data);
4475         ObjMgrSetDirtyFlag (bfp->input_entityID, TRUE);
4476         ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
4477         if (change_notify == NULL) {
4478           ObjMgrSendMsg (OM_MSG_CREATE, bfp->input_entityID, 0, 0);
4479         }
4480       }
4481     }
4482   }
4483 }
4484 
4485 
LclGetSequinAppParam(CharPtr section,CharPtr type,CharPtr dflt,CharPtr buf,Int2 buflen)4486 static Int2 LclGetSequinAppParam (CharPtr section, CharPtr type, CharPtr dflt, CharPtr buf, Int2 buflen)
4487 
4488 {
4489   Int2  rsult;
4490 
4491   rsult = GetAppParam ("SEQUINCUSTOM", section, type, NULL, buf, buflen);
4492   if (rsult) return rsult;
4493   rsult = GetAppParam ("SEQUIN", section, type, dflt, buf, buflen);
4494   return rsult;
4495 }
4496 
LessClickingOptionOnStartup(void)4497 static Boolean LessClickingOptionOnStartup (void)
4498 {
4499   Char            str [32];
4500   Boolean         less_clicking = FALSE;
4501 
4502   if (LclGetSequinAppParam ("SETTINGS", "LESS_CLICKING", NULL, str, sizeof (str))) {
4503     if (StringICmp (str, "TRUE") == 0) {
4504       less_clicking = TRUE;
4505     }
4506   }
4507   return less_clicking;
4508 }
4509 
4510 
SmartSeqEntryViewGenFunc(Pointer data)4511 extern Int2 LIBCALLBACK SmartSeqEntryViewGenFunc (Pointer data)
4512 
4513 {
4514   BioseqContextPtr   bcp;
4515   BioseqViewFormPtr  bfp;
4516   BioseqPtr          bsp;
4517   ForM               f;
4518 /* ObjMgrDataPtr      omdp; */
4519   OMProcControlPtr   ompcp;
4520   OMUserDataPtr      omudp;
4521   Boolean            reusing;
4522   ValNodePtr         sdp;
4523   SeqEntryPtr        sep;
4524   SeqIdPtr           sip;
4525   Char               str [PATH_MAX];
4526   SeqViewProcsPtr    svpp;
4527   CharPtr            timestamptitle;
4528   ValNodePtr         ttl;
4529   Int4               val;
4530   WindoW             w;
4531 
4532   ompcp = (OMProcControlPtr) data;
4533   bsp = NULL;
4534   if (ompcp == NULL || ompcp->proc == NULL) return OM_MSG_RET_ERROR;
4535   switch (ompcp->input_itemtype) {
4536     case OBJ_BIOSEQ :
4537       bsp = (BioseqPtr) ompcp->input_data;
4538       break;
4539     case OBJ_BIOSEQSET :
4540       return OM_MSG_RET_ERROR;
4541     case 0 :
4542       return OM_MSG_RET_ERROR;
4543     default :
4544       return OM_MSG_RET_ERROR;
4545   }
4546   /* if (bsp == NULL) return OM_MSG_RET_ERROR; */
4547   str [0] = '\0';
4548   /* StringCpy (str, "no record"); */
4549   if (bsp != NULL) {
4550     sip = SeqIdFindWorst (bsp->id);
4551     if (sip == NULL) return OM_MSG_RET_ERROR;
4552     SeqIdWrite (sip, str, PRINTID_REPORT, sizeof (str));
4553     sep = GetTopSeqEntryForEntityID (ompcp->input_entityID);
4554     if (IsAGenomeRecord (sep)) {
4555       bcp = BioseqContextNew (bsp);
4556       ttl = NULL;
4557       sdp = BioseqContextGetSeqDescr (bcp, Seq_descr_title, NULL, NULL);
4558       while (sdp != NULL) {
4559         ttl = sdp;
4560         sdp = BioseqContextGetSeqDescr (bcp, Seq_descr_title, sdp, NULL);
4561       }
4562       BioseqContextFree (bcp);
4563       if (ttl != NULL && (! StringHasNoText ((CharPtr) ttl->data.ptrvalue))) {
4564         StringNCpy_0 (str, (CharPtr) ttl->data.ptrvalue, sizeof (str));
4565       }
4566     }
4567   }
4568   /* append timestamp to title */
4569   timestamptitle = GetAppProperty ("SmartSequinTimeStampTitle");
4570   if (timestamptitle != NULL) {
4571     StringCat (str, " ");
4572     StringCat (str, timestamptitle);
4573   }
4574   w = NULL;
4575   reusing = FALSE;
4576   if (smartBioseqViewForm != NULL) {
4577     svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
4578     if (svpp != NULL && svpp->forceSeparateViewer) {
4579       w = (WindoW) CreateNewSeqEntryViewFormEx (-50, -33, str, bsp, NULL, ompcp->input_entityID,
4580                                                 ompcp->input_itemID, ompcp->input_itemtype, TRUE);
4581       if (smartBioseqViewForm == NULL) {
4582         smartBioseqViewForm = (ForM) w;
4583       }
4584     } else {
4585       /*
4586       bfp = (BioseqViewFormPtr) GetObjectExtra (smartBioseqViewForm);
4587 
4588       if (bfp != NULL) {
4589           if (bfp->input_entityID > 0) {
4590             omdp = ObjMgrGetData (bfp->input_entityID);
4591             if (omdp != NULL && omdp->dirty) {
4592                 SendMessageToForm (smartBioseqViewForm, VIB_MSG_ACCEPT);
4593                 ObjMgrSetDirtyFlag (bfp->input_entityID, FALSE);
4594             } else if(Visible((WindoW)smartBioseqViewForm) ||
4595                       Nlm_IconicWindow((WindoW)smartBioseqViewForm)) {
4596                 SendMessageToForm (smartBioseqViewForm, VIB_MSG_RESET);
4597             }
4598           }
4599       }
4600 
4601       CleanSmartViewer (bfp);
4602       Update ();
4603       */
4604       w = (WindoW) smartBioseqViewForm;
4605       SetTitle (w, str);
4606       reusing = TRUE;
4607     }
4608   } else {
4609     w = (WindoW) CreateNewSeqEntryViewFormEx (-50, -33, str, bsp, NULL, ompcp->input_entityID,
4610                                               ompcp->input_itemID, ompcp->input_itemtype, TRUE);
4611     if (smartBioseqViewForm == NULL) {
4612       smartBioseqViewForm = (ForM) w;
4613     }
4614   }
4615   bfp = (BioseqViewFormPtr) GetObjectExtra (w);
4616   if (bfp != NULL) {
4617     bfp->bvd.bsp = bsp;
4618     SafeHide (bfp->targetControl);
4619     Update ();
4620     Reset (bfp->targetControl);
4621     val = PopulateTarget (bfp);
4622     SetValue (bfp->targetControl, (Int2) val + 1);
4623     SafeShow (bfp->targetControl);
4624     bfp->input_entityID = ompcp->input_entityID;
4625     bfp->input_itemID = ompcp->input_itemID;
4626     bfp->input_itemtype = ompcp->input_itemtype;
4627     bfp->this_itemtype = OBJ_BIOSEQ;
4628     bfp->procid = ompcp->proc->procid;
4629     bfp->proctype = ompcp->proc->proctype;
4630     if (bsp != NULL) {
4631       bfp->this_subtype = bsp->repr;
4632       bfp->docuid = GetUidFromBsp (bsp);
4633     } else {
4634       bfp->this_subtype = Seq_repr_raw;
4635       bfp->docuid = 0;
4636     }
4637     if (bsp == NULL) {
4638     } else if (ISA_na (bsp->mol)) {
4639       bfp->doctype = TYP_NT;
4640     } else if (ISA_aa (bsp->mol)) {
4641       bfp->doctype = TYP_AA;
4642     }
4643     bfp->userkey = OMGetNextUserKey ();
4644     omudp = ObjMgrAddUserData (ompcp->input_entityID, ompcp->proc->procid,
4645                                ompcp->proc->proctype, bfp->userkey);
4646 
4647     if (omudp != NULL) {
4648       omudp->userdata.ptrvalue = (Pointer) bfp;
4649       omudp->messagefunc = BioseqViewMsgFunc;
4650     }
4651     if (reusing) {
4652       ObjMgrSendMsg (OM_MSG_UPDATE, bfp->input_entityID, 0, 0);
4653     }
4654     SendMessageToForm (bfp->form, VIB_MSG_CHANGE);
4655   }
4656   if (bsp != NULL) {
4657     Show (w);
4658   }
4659   if (bfp != NULL) {
4660     svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
4661     if (svpp != NULL && svpp->createToolBar != NULL) {
4662       f = MakeToolFormForBioseqView ((BaseFormPtr) bfp, svpp->createToolBar);
4663       Show (f);
4664     }
4665   }
4666   Select (w);
4667 
4668   AutofixOnStartup ((BaseFormPtr) bfp, NULL, NULL);
4669   if (LessClickingOptionOnStartup()) {
4670     Message (MSG_POSTERR, "Opened new record");
4671   }
4672 
4673   return OM_MSG_RET_DONE;
4674 }
4675 
4676