NCBI C Toolkit Cross Reference

C/desktop/bspview.c


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

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.