home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / DBio / DSeqEd.cpp < prev    next >
Encoding:
Text File  |  1995-12-17  |  37.8 KB  |  1,524 lines  |  [TEXT/R*ch]

  1. // DSeqEd.cpp -- one sequence edit view/window 
  2. // d.g.gilbert, 1991-94 
  3.  
  4.  
  5. #include "DSeqEd.h"
  6. #include <ncbi.h>
  7. #include <dgg.h>
  8. #include <Dvibrant.h>
  9. #include <DControl.h>
  10. #include <DWindow.h>
  11. #include <DTableView.h>
  12. #include <DApplication.h>
  13. #include <DTask.h>
  14. #include <DUtil.h>
  15. #include <DDialogText.h>
  16. #include <DMenu.h>
  17. #include <DFindDlog.h>
  18.  
  19. #include "DSeqFile.h"
  20. #include "DSeqDoc.h"
  21. #include "DSeqCmds.h"
  22.  
  23.  
  24.  
  25.  
  26.  
  27. Local Nlm_FonT    gPromptFont = Nlm_programFont;
  28. //Local Nlm_FonT    gSeqFont = Nlm_programFont;
  29.  
  30. enum SeqedIDs {
  31.     mReformatHit = 2101,
  32.     ceNAM, cTEVW, ctBEG, ctEND, ctSEL, ctLEN,  ctCHK, ctTYP, cmCOD    
  33. };
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. // class DSeqFindDialog
  42.  
  43. class DSeqFindDialog : public DFindDialog {
  44. public:
  45.     DSequence* fSequence;
  46.     DSeqedView* fSeqedView;
  47.     char    * fLastTarget;
  48.     long        fLastMatch;
  49.     DSeqFindDialog( DSequence* itsSeq, DSeqedView* itsView);
  50.     virtual void DoFind();
  51.     virtual void BuildDlog();
  52. };
  53.  
  54. DSeqFindDialog::DSeqFindDialog( DSequence* itsSeq, DSeqedView* itsView) :
  55.         fSequence(itsSeq), fSeqedView( itsView), 
  56.         fLastTarget(NULL), fLastMatch(-1)
  57. {
  58. }
  59.  
  60. void DSeqFindDialog::BuildDlog()
  61. {
  62.     DFindDialog::BuildDlog();
  63.  
  64.     DView* av;
  65.     av= FindSubview(replaceId); if (av) { av->Disable(); } //av->Hide();
  66.     av= FindSubview(replaceFindId); if (av) { av->Disable();  }
  67.     av= FindSubview(replaceAllId); if (av) { av->Disable(); }
  68.     av= FindSubview(cBackwards);     if (av) { av->Disable(); }
  69.     av= FindSubview(cFullWord); if (av) { av->Disable(); }
  70.     av= FindSubview(cCaseSense); if (av) { av->Disable(); }
  71.     if (fReplaceText) fReplaceText->Disable();
  72. }
  73.  
  74. void DSeqFindDialog::DoFind() 
  75. {
  76.     long    firstBase, nBases, match;
  77.     short n1, n2;
  78.     const char    *target;
  79.     Boolean back;
  80.     
  81.     fSequence->UpdateFlds();  
  82.     fSeqedView->GetSelection( n1, n2);
  83.     firstBase= n1;
  84.     nBases= 0; //n2 - n1;
  85.     fSequence->SetSelection( firstBase, nBases);
  86.     target= this->GetFind();
  87.     back    = this->Backwards();
  88.     if (target && *target) {
  89.         if (fLastTarget && StringCmp(target, fLastTarget)==0 && firstBase == fLastMatch)
  90.             match= fSequence->SearchAgain();
  91.         else {
  92.             if (fLastTarget) MemFree(fLastTarget);
  93.             fLastTarget= StrDup(target);
  94.             match= fSequence->Search( (char*)target, back);
  95.             }
  96.         fLastMatch= match;
  97.         if (match>=0) {
  98.             nBases= StrLen(target);
  99.             fSequence->SetSelection( match, nBases);
  100.             fSeqedView->SetSelection( match, match+nBases);
  101.             }
  102.         }
  103. }                
  104.  
  105.  
  106.  
  107.  
  108.  
  109. // DSeqedView -----------------------------
  110.  
  111.  
  112. DSeqedView::DSeqedView(long id, DView* itsSuperior, DSeqedWindow* itsDoc, DSequence* aSeq,
  113.                                  short width, short height) :
  114.     DDialogScrollText( id, itsSuperior, width, height, gSeqFont, true) // true==wrap
  115.  
  116. {
  117.   fOldStart= fOldEnd= fOldLen= -1;
  118.     fOldKind= -1; 
  119.     fOldCheck= -1;
  120.  
  121.     //fControlChars = fControlChars - [chTab];
  122.     
  123.     Nlm_RecT         arect; 
  124.     Nlm_LoadRect(&arect,0,0,0,0);
  125.     fOldDest= arect;
  126.     fOldView= arect;
  127.     fChanged= FALSE;
  128.  
  129.     // FailNIL( aSeq); 
  130.     if (!aSeq) { delete this; return; }
  131.     fSequence= aSeq;
  132.     fDoc= itsDoc;
  133.  
  134.   fSeqStart = fDoc->fSeqStart;
  135.   fSeqEnd = fDoc->fSeqEnd;
  136.   fSeqSel = fDoc->fSeqSel;
  137.   fSeqLen = fDoc->fSeqLen;
  138.   fSeqCheck = fDoc->fSeqCheck;
  139.   //fSeqTyp = fDoc->fSeqTyp;
  140.   fCodePop = fDoc->fCodePop;
  141.   fCodePop->SetValue( fSequence->Kind());
  142.  
  143.     //SetKeyHandler(this); //?? also need this call in a window activate/deactivate method??
  144.  
  145.     this->SetResize( DView::relsuper, DView::relsuper);
  146.     this->SetText( fSequence->Bases());
  147.  
  148.     UpdateCtls(TRUE); //??
  149. }
  150.  
  151.  
  152. DSeqedView::~DSeqedView()
  153. {
  154.     if (fChanged && fDoc && fDoc->fMainDoc)    
  155.         fDoc->fMainDoc->Dirty(); //((DSeqDoc*)fSuperior)->Dirty();
  156. }
  157.  
  158.  
  159. void DSeqedView::SetSeq(DSequence* aSeq) 
  160. {
  161.     fSequence= aSeq;
  162.     this->SetText( fSequence->Bases());
  163.     UpdateCtls(true);
  164.     //this->Invalidate(); //??
  165. }
  166.  
  167. void DSeqedView::UpdateCtls(Boolean forceIndex)  //call this when seq indices change
  168. {    
  169.      char    newNum[256];
  170.      short    n1, n2;
  171.     Boolean        newrange, didChange;
  172.     Nlm_RecT        adest, aview, bview;
  173.      
  174.      
  175.     newrange= FALSE;    
  176.     didChange= FALSE;
  177.     adest= fOldDest;
  178.     aview= fOldView;
  179.     this->ViewRect(bview);
  180.     
  181. #if 0
  182.     if (!Nlm_EqualRect( &aview, &bview)) fSeqHindex->Invalidate();  
  183.         
  184.     if (forceIndex 
  185.      || !Nlm_EqualRect(&adest, (*fHTE)->destRect) 
  186.      || !Nlm_EqualRect(&aview, &bview)) {
  187.         fSeqIndex->Invalidate();  
  188.         fOldDest= (*fHTE)->destRect;
  189.         fOldView= bview;
  190.         }
  191. #endif         
  192.         
  193.     this->GetSelection( n1, n2);
  194.     if (n1 != fOldStart) {
  195.         sprintf(newNum, "%d", n1+1);
  196.         fSeqStart->SetTitle(newNum);
  197.         fOldStart= n1;
  198.         newrange= TRUE;
  199.         }
  200.     
  201.     if (n2 != fOldEnd) {
  202.         short val;
  203.         if (n2 > n1) val= n2; else val= n2+1;
  204.         sprintf(newNum, "%d", val);
  205.         fSeqEnd->SetTitle(newNum);
  206.         fOldEnd= n2;
  207.         newrange= TRUE;
  208.         }
  209.  
  210.     if (newrange) {
  211.         sprintf(newNum, "%d", n2 - n1);
  212.         fSeqSel->SetTitle(newNum);
  213.         }
  214.  
  215.     if (fSequence->Checksum() != fOldCheck) {
  216.         sprintf(newNum, "%-8lx", fSequence->Checksum());
  217.         fSeqCheck->SetTitle(newNum);
  218.         fOldCheck= fSequence->Checksum();
  219.         didChange= TRUE;
  220.         }
  221.         
  222.     if (fSequence->Kind() != fOldKind) {
  223.       fCodePop->SetValue( fSequence->Kind()+1);         
  224.         //fSequence->SetKind(fCodePop->GetValue()-1); 
  225.         fOldKind= fSequence->Kind();
  226.         didChange= TRUE;
  227.         }
  228.         
  229.     long len= this->TextLength();
  230.     if (len != fOldLen) {
  231.         sprintf(newNum, "%d", len);
  232.         fSeqLen->SetTitle(newNum);
  233.         //fSeqIndex->AdjustFrame(); //! change index size, ?do this only when nlines changes?
  234.         fOldLen= len;
  235.         didChange= TRUE;
  236.         }
  237.         
  238.     if (didChange) this->fChanged= TRUE;
  239. }
  240.  
  241.  
  242.  
  243. //-- Override some TTEView routines that can change selection && scroll
  244. // SynchView is called only/just after some, but not all, RecalcTexts 
  245. // main usage will be from Resize 
  246.  
  247. void DSeqedView::selectAction()
  248. {
  249.     DDialogScrollText::selectAction();
  250.     gCursor->ibeam();
  251.     SetKeyHandler(this); //?? also need this call in a window activate/deactivate method??
  252.     this->UpdateCtls(TRUE);
  253. }
  254.  
  255. void DSeqedView::deselectAction()
  256. {
  257.     SetKeyHandler(NULL); //?? also need this call in a window activate/deactivate method??
  258.     fDoc->SetEditText(NULL);
  259.     gCursor->arrow();
  260.     DDialogScrollText::deselectAction();
  261. }
  262.  
  263.  
  264. /****
  265. class DKeyCallback
  266. {
  267. public:
  268.     DKeyCallback();
  269.     virtual ~DKeyCallback();
  270.     virtual void SetKeyHandler(DKeyCallback* handler);
  271.   virtual void ProcessKey( char c) = 0;
  272. };
  273. *****/
  274.  
  275. void DSeqedView::ProcessKey( char c)
  276. {
  277.     //fSequence->SetKind(fCodePop->GetValue()-1); //?? why this on each char?? 
  278.     if ( IsEnabled()) { 
  279.             if (!fSequence->GoodChar(c)) {
  280.                 Nlm_Beep(); //gApplication->Beep(1);  
  281.                 // Flush further keystrokes ?
  282.                 }
  283.         UpdateCtls(FALSE);
  284.         }
  285. }
  286.  
  287.  
  288.  
  289.  
  290.  
  291. Boolean DSeqedView::DoMenuTask(long tasknum, DTask* theTask)
  292. {
  293.     DWindow* win = NULL;
  294.     
  295.     switch (tasknum) {
  296.  
  297.         case DSeqDoc::cFindORF:
  298.             {
  299.                 long    start, stop;
  300.                 short n1, n2;
  301.                 
  302.                 fSequence->UpdateFlds();  
  303.                 this->GetSelection( n1, n2);
  304.                 if (n2 > n1+1) n1++; // !? offset sel start so we can repeat call
  305.                 fSequence->SetSelection( n1, 0);
  306.                 fSequence->SearchORF( start, stop);
  307.                 if (start>=0) {
  308.                     if (stop<start) stop= fSequence->LengthF(); //??
  309.                     fSequence->SetSelection( start, stop - start);
  310.                     this->SetSelection( start, stop);
  311.                     }
  312.             }                
  313.             return true;
  314.  
  315.         case DSeqDoc::cRevSeq:
  316.         case DSeqDoc::cCompSeq:
  317.         case DSeqDoc::cRevCompSeq:
  318.         case DSeqDoc::cDna2Rna: 
  319.         case DSeqDoc::cRna2Dna:
  320.         case DSeqDoc::cToUpper: 
  321.         case DSeqDoc::cToLower:
  322.         case DSeqDoc::cDegap:
  323.         case DSeqDoc::cLockIndels:
  324.         case DSeqDoc::cUnlockIndels:
  325.         //case DSeqDoc::cConsensus:
  326.         case DSeqDoc::cTranslate:
  327.             {
  328.             long    firstBase, nBases;
  329.             short n1, n2;
  330.             DSeqList * aSeqList= NULL;
  331.             DSeqChangeCmd *    cmd = NULL;  
  332.             DSeqDoc* maindoc= this->fDoc->fMainDoc;
  333.             
  334.             //GetSelection( TRUE, TRUE, aSeqList, firstBase, nBases);
  335.             fSequence->UpdateFlds();  
  336.             this->GetSelection( n1, n2);
  337.             firstBase= n1;
  338.             nBases= n2 - n1;
  339.             fSequence->SetSelection( firstBase, nBases);
  340.             aSeqList= new DSeqList();
  341.             aSeqList->InsertLast(fSequence);
  342.             
  343.             switch (tasknum) {
  344.               case DSeqDoc::cRevSeq            : cmd= new DSeqReverseCmd( maindoc, this, aSeqList);  break;
  345.                 case DSeqDoc::cCompSeq        : cmd= new DSeqComplementCmd(  maindoc, this, aSeqList); break;
  346.                 case DSeqDoc::cRevCompSeq : cmd= new DSeqRevComplCmd(  maindoc, this, aSeqList); break;
  347.                 case DSeqDoc::cDna2Rna        : cmd= new DSeqDna2RnaCmd(  maindoc, this, aSeqList); break;
  348.                 case DSeqDoc::cRna2Dna        :    cmd= new DSeqRna2DnaCmd(  maindoc, this, aSeqList); break;
  349.                 case DSeqDoc::cToUpper        :    cmd= new DSeqUppercaseCmd(  maindoc, this, aSeqList); break;
  350.                 case DSeqDoc::cToLower        :    cmd= new DSeqLowercaseCmd(  maindoc, this, aSeqList); break;
  351.                 case DSeqDoc::cDegap            :    cmd= new DSeqCompressCmd(  maindoc, this, aSeqList); break;
  352.                 case DSeqDoc::cLockIndels    :    cmd= new DSeqLockIndelsCmd( maindoc, this, aSeqList); break;
  353.                 case DSeqDoc::cUnlockIndels: cmd= new DSeqUnlockIndelsCmd( maindoc, this, aSeqList); break;
  354.                 case DSeqDoc::cTranslate    :    cmd= new DSeqTranslateCmd( maindoc, this, aSeqList); break;
  355.                 
  356.                 default:
  357.                     delete aSeqList;
  358.                     Message(MSG_OK,"DSeqedView::method not ready.");
  359.                     return true;
  360.                 
  361.               }
  362.           if (cmd) {
  363.               if (cmd->Initialize()) PostTask( cmd);
  364.               else {
  365.                   delete cmd;
  366.                   Message(MSG_OK,"DSeqedView::method failed.");
  367.                     }
  368.               }
  369.             return true;    
  370.             }
  371.         
  372.         case DSeqDoc::cPrettyPrint:  //MakeAlnPrint();
  373.         case DSeqDoc::cREMap:                //MakeSeqPrint( TRUE); 
  374.         case DSeqDoc::cDotPlot:            //MakeDottyPlot();
  375.             Message(MSG_OK,"DSeqedView::method not ready.");
  376.             return true;
  377.  
  378.         default: 
  379.             return DTaskMaster::DoMenuTask(tasknum, theTask);
  380.         }
  381.  
  382. }
  383.  
  384.  
  385. Boolean DSeqedView::IsMyAction(DTaskMaster* action) 
  386. {
  387.     long  menuid= 0;
  388.     if (action->fSuperior)  menuid = action->fSuperior->Id();
  389.     switch(action->Id()) {
  390.         case DApplication::kCut:
  391.         case DApplication::kCopy:
  392.         case DApplication::kPaste:
  393.         case DApplication::kClear:
  394.         case DApplication::kSelectAll:
  395.             return DDialogText::IsMyAction(action);
  396.         }
  397.         
  398. #if 0            
  399.  if (action->Id() == kColorButHit) {
  400.         fUseColor= ((DView*)action)->GetStatus();
  401.         fAlnView->Invalidate();
  402.       return true;
  403.       }
  404.     else 
  405. #endif
  406.         return DoMenuTask(action->Id(), NULL);
  407. }
  408.             
  409.  
  410.  
  411.  
  412. #if FIX_LATER
  413. pascal void TSeqedView::DoMenuCommand(aCommandNumber:CommandNumber); // override 
  414. VAR
  415.         TSeqTranslateCmd        aSeqTranslateCmd;
  416.         TSeqReverseCmd        aSeqReverseCmd;
  417.         TSeqRevComplCmd        aSeqRevComplCmd;
  418.         TSeqComplementCmd        aSeqComplementCmd;
  419.         TSeqCompressCmd        aSeqCompressCmd;
  420.         TSeqDna2RnaCmd        aSeqDna2RnaCmd;
  421.         TSeqRna2DnaCmd        aSeqRna2DnaCmd;
  422.         TSeqLockIndelsCmd        aSeqLockIndelsCmd;
  423.         TSeqUnlockIndelsCmd        aSeqUnlockIndelsCmd;
  424.     
  425.     pascal void MakeSeqPrint(Boolean doREMap)
  426.     VAR
  427.             TREMapDocument        aREMapDoc;
  428.             aSeqPrDoc    : TSeqPrintDocument;
  429.             longint        firstBase, nBases;
  430.     {
  431.         fSequence->UpdateFlds(); //!? need for New seq...
  432.         firstBase= this.(*fHTE)->selStart; 
  433.         nBases= this.(*fHTE)->selEnd - firstBase;  
  434.         if (doREMap) {
  435.             New(aREMapDoc);
  436.             FailNIL(aREMapDoc);
  437.             aREMapDoc->IREMapDocument(kPrintClipType, fDocument, fSequence, firstBase, nbases);
  438.             gSeqAppApplication->OpenNewDocument(aREMapDoc);  
  439.             }        else {
  440.             New(aSeqPrDoc);
  441.             FailNIL(aSeqPrDoc);
  442.             aSeqPrDoc->ISeqPrintDocument(kPrintClipType, fDocument, fSequence, firstBase, nbases);
  443.             gSeqAppApplication->OpenNewDocument(aSeqPrDoc);  
  444.             }
  445.     }
  446.     
  447.     pascal void GetSeqList( TSeqList VAR aSeqList)
  448.     longint        VAR firstBase, nBases;
  449.     {
  450.         fSequence->UpdateFlds(); //!? need for New seq...
  451.         firstBase= (*fHTE)->selStart;
  452.         nBases= (*fHTE)->selEnd - firstBase;
  453.         fSequence->SetSelection( firstBase, nBases);
  454.         aSeqList= TSeqList(NewList); 
  455.         FailNIL( aSeqList);
  456.         aSeqList->InsertLast(fSequence);
  457.     }
  458.  
  459.     pascal void    DoSeqChangeCommand( TSeqChangeCmd aCommand)
  460.     VAR        aSeqList: TSeqList; 
  461.     {
  462.         FailNIL(aCommand);
  463.         GetSeqList( aSeqList);
  464.         aCommand->ISeqChangeCmd( TAlnDoc(fDocument), this, aSeqList); 
  465.         PostCommand( aCommand);
  466.     }
  467.  
  468. {
  469.     switch (aCommandNumber) {
  470.         cTranslateSeq: {
  471.                 New(aSeqTranslateCmd);
  472.                 DoSeqChangeCommand(aSeqTranslateCmd);
  473.                 }
  474.         cReverseSeq: {
  475.                 New(aSeqReverseCmd);
  476.                 DoSeqChangeCommand(aSeqReverseCmd);
  477.                 }
  478.         cComplementSeq: {
  479.                 New(aSeqComplementCmd);
  480.                 DoSeqChangeCommand(aSeqComplementCmd);
  481.                 }
  482.         cRevComplement: {
  483.                 New(aSeqRevComplCmd);
  484.                 DoSeqChangeCommand(aSeqRevComplCmd);
  485.                 }
  486.         cCompress: {
  487.                 New(aSeqCompressCmd);
  488.                 DoSeqChangeCommand(aSeqCompressCmd);
  489.                 }
  490.         cLockIndels: {
  491.                 New(aSeqLockIndelsCmd);
  492.                 DoSeqChangeCommand(aSeqLockIndelsCmd);
  493.                 }
  494.         cUnlockIndels: {
  495.                 New(aSeqUnlockIndelsCmd);
  496.                 DoSeqChangeCommand(aSeqUnlockIndelsCmd);
  497.                 }
  498.         cDna2Rna: {
  499.                 New(aSeqDna2RnaCmd);
  500.                 DoSeqChangeCommand(aSeqDna2RnaCmd);
  501.                 }
  502.         cRna2Dna: {
  503.                 New(aSeqRna2DnaCmd);
  504.                 DoSeqChangeCommand(aSeqRna2DnaCmd);
  505.                 }
  506.                     
  507.         cPrettyPrint: MakeSeqPrint( FALSE);
  508.         cRestrictMap: MakeSeqPrint( TRUE);
  509.           
  510.         default:
  511.             inherited::DoMenuCommand(aCommandNumber);
  512.         }
  513.  
  514.     UpdateCtls(FALSE);
  515. }
  516.  
  517. pascal void TSeqedView::DoSetupMenus(void) // override 
  518. VAR  haveSel: boolean;
  519. {
  520.   inherited::DoSetupMenus();    
  521.     
  522.     //haveSel= ((*fHTE)->selEnd - (*fHTE)->selStart) > 0; 
  523.     haveSel= TRUE; 
  524.  
  525.     Enable( cReverseSeq, haveSel); 
  526.     Enable( cComplementSeq, haveSel); 
  527.     Enable( cRevComplement, haveSel); 
  528.     Enable( cCompress, haveSel); 
  529.     Enable( cLockIndels, haveSel); 
  530.     Enable( cUnlockIndels, haveSel); 
  531.     Enable( cDna2Rna, haveSel); 
  532.     Enable( cRna2Dna, haveSel); 
  533.     Enable( cTranslateSeq, haveSel); 
  534.     
  535.     Enable( cPrettyPrint, TRUE); 
  536.     Enable( cRestrictMap, TRUE); 
  537. }
  538.  
  539.  
  540. pascal void TSeqedView::DoMouseCommand(VPoint VAR theMouse, TToolboxEvent event,
  541.                                                Point hysteresis) // override 
  542. {
  543.     inherited::DoMouseCommand(theMouse,event,hysteresis);
  544.     UpdateCtls(FALSE);
  545. }
  546.  
  547.  
  548.  //keep cursor at arrow when teview is not selected (inactive "edittext")
  549. pascal void TSeqedView::DoSetCursor(VPoint localPoint, RgnHandle cursorRegion)    // override 
  550. {
  551.     if GetWindow->fTarget == this then 
  552.         inherited::DoSetCursor(localPoint, cursorRegion);
  553. }
  554.  
  555.  
  556. pascal TSeqedView::HandleMouseDown( VPoint theMouse, TToolboxEvent event, 
  557.                              hysteresis: Point):Boolean; // override 
  558. //TView method -- note this is Generic for any TEView...
  559. {        
  560.     if (GetWindow->fTarget != this) { 
  561.         /*---
  562.         TDialogView        VAR aDlog; 
  563.         aDlog = TDialogView(GetDialogView);   
  564.         if ((aDlog!=NULL)) if (!aDlog->DeselectCurrentEditText()) ;
  565.         ---*/
  566.         /*---
  567.          Else if fTarget == otherTEView)
  568.             otherTEView->InstallSelection(TRUE,FALSE);
  569.         -----*/
  570.         // gApplication->SetTarget(this);
  571.         HandleMouseDown= BecomeTarget;   //! turn on our TEview event handler
  572.         }    else
  573.       HandleMouseDown= inherited::HandleMouseDown(theMouse,event,hysteresis);
  574. }
  575.  
  576.  
  577. #endif // FIX_LATER
  578.  
  579.  
  580.  
  581.  
  582. // TSeqIndex ----------------------------------
  583.  
  584.  
  585. #if FIX_LATER
  586.  
  587. pascal void TSeqIndex::Initialize(void) // override 
  588. {
  589.     inherited::Initialize();
  590.     fTEView    = NULL;
  591. }
  592.  
  593. pascal void TSeqIndex::CalcMinFrame(VRect VAR minFrame) // override 
  594. // THIS WAS bombing us on initial call to CreateViews.. until we IRes'd
  595. VAR
  596.     VRect        superExtent;
  597. {
  598.   inherited::CalcMinFrame(minFrame);
  599.     if (fSuperView!=NULL) {
  600.         fSuperView->GetExtent(superExtent);
  601.         minFrame.bottom= max(minFrame.bottom, superExtent.bottom);
  602.         }
  603.     if ((fTEView!=NULL) && (fTEView->fHTE!=NULL))
  604.         minFrame.bottom= max(minFrame.bottom, 10+TEGetHeight(0,fTEView.(*fHTE)->nlines,fTEView->fHTE));
  605. }
  606.  
  607. pascal void TSeqIndex::Draw(VRect area) // override 
  608. VAR
  609.     rect        vrect ;
  610.     integer        cat, il, h, v, v1, nl, vend, ih, ws ;
  611.     nums    : Str255;
  612.     ptop    : point;
  613. {
  614.     if ((fTEView!=NULL)) {
  615.         vrect= fTEView.(*fHTE)->viewrect;
  616.         h        = area.right-3;
  617.         v        = vrect.top;
  618.         vend= area.bottom;
  619.         
  620.         cat = TEGetOffset(vrect.topleft,fTEView->fHTE);
  621.         il  = 0;
  622.         nl= fTEView.(*fHTE)->nlines;
  623.         while ( (il < nl) && (cat > fTEView.(*fHTE)->lineStarts[il]) do il= il+1;
  624.         while ( (v < vend) && (il < nl)){
  625.             v1= v + TEGetHeight( il, il, fTEView->fHTE);
  626.             if ((v1 >= area.top) && (v <= vend)) {
  627.                 cat= fTEView.(*fHTE)->lineStarts[il];
  628.                 NumToString( cat, nums);
  629.                 moveto( h-StringWidth(nums), v1);
  630.                 drawString(nums); 
  631.                 }
  632.             v= v1;  
  633.             il= il + 1;
  634.             }
  635.         }
  636.     inherited::Draw(area); //!?
  637. }
  638.  
  639. #endif //FIX_LATER
  640.  
  641.  
  642.  
  643.  
  644. // TSeqHIndex ----------------------------
  645.  
  646. #if FIX_LATER
  647.  
  648. pascal void TSeqHIndex::Draw(VRect area) // override 
  649. var
  650.     rect        vrect ;
  651.     integer        cat, ecat, il, h, v, vend, ws ;
  652.     nums    : Str255;
  653.     pt        : point;
  654. {
  655.     if ((fTEView!=NULL)) {
  656.         vrect= fTEView.(*fHTE)->viewrect;
  657.         v        = area.bottom;
  658.         vend= area.right;
  659.         cat = TEGetOffset(vrect.topleft,fTEView->fHTE); //!? is pt rel to view or dest ?
  660.     
  661.         WITH fTEView.(*fHTE)^){
  662.             il  = 0;
  663.             while ( (il < nlines) && (cat >= lineStarts[il]))il= il+1;
  664.             ecat= lineStarts[il];
  665.             if (il>0) cat= lineStarts[il-1];
  666.             }
  667.         
  668.         il= 5; 
  669.         cat= cat + 4; //? skip 1
  670.         do {
  671.             pt= TEGetPoint(cat, fTEView->fHTE);
  672.             moveto(pt.h, v);
  673.     
  674.             if ((il mod 10 == 0)) {
  675.                 line(0,-3);
  676.                 NumToString( il, nums);
  677.                 ws= StringWidth(nums);
  678.                 move(-ws div 2,-1);
  679.                 drawstring(nums);
  680.                 }            else 
  681.                 line(0,-8);
  682.             cat= cat + 5;
  683.             il= il+5;
  684.         } while (!((pt)).h >= area.right) || (cat >= ecat);
  685.         }
  686.     inherited::Draw(area);
  687. }
  688.  
  689.  
  690. #endif //FIX_LATER
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698. // DSeqedWindow ------------------------
  699.  
  700.  
  701.  
  702.     
  703. DSeqedWindow::DSeqedWindow(long id, DTaskMaster* itsSuperior, DSeqDoc* itsSeqDoc, DSequence* aSeq,
  704.                                     short winwidth, short winheight, short winleft, short wintop, char* title) :
  705.     DWindow(id, itsSuperior, DWindow::document, winwidth, winheight, winleft, wintop, title)
  706. {    
  707.     DView* super = this;
  708.     DPrompt* pr;
  709.     DCluster* clu;
  710.     
  711.         // fix this later...
  712.     gPromptFont= Nlm_programFont;
  713.     //gSeqFont     = Nlm_programFont;
  714.  
  715.     fSequence= aSeq; // ?? Clone it for safety ??
  716.     fMainDoc= itsSeqDoc;
  717.     
  718.   clu= new DCluster(0,super,0,0,true,NULL);
  719.   super= clu;
  720.   pr = new DPrompt(0, super, "Name:", 0, 0, gPromptFont, justleft);
  721.   super->NextSubviewToRight();
  722.   fSeqName = new DEditText( ceNAM, super, aSeq->Name(), 20);  
  723.   
  724.  
  725.     super= this;
  726.     super->NextSubviewBelowLeft();
  727.     
  728.   clu= new DCluster(0,super,0,0,false,"Sequence");
  729.     super= clu;
  730.         
  731.   pr = new DPrompt(0, super, " length:", 0, 0, gPromptFont, justleft);
  732.   super->NextSubviewToRight();
  733.      fSeqLen = new DPrompt(ctLEN, super, "00000", 0, 0, gPromptFont, justright);
  734.   super->NextSubviewToRight();
  735.   
  736.   pr = new DPrompt(0, super, " checksum:", 0, 0, gPromptFont, justleft);
  737.   super->NextSubviewToRight();
  738.   fSeqCheck = new DPrompt(ctCHK, super, "0000000", 0, 0, gPromptFont, justright);
  739.   super->NextSubviewToRight();
  740.   
  741.   pr = new DPrompt(0, super, " type:", 0, 0, gPromptFont, justleft);
  742.   super->NextSubviewToRight();
  743.   //fSeqTyp   = new DPrompt(ctTYP, super, "Unknown type", 0, 0, gPromptFont, justleft);
  744.   //super->NextSubviewToRight();
  745.   fCodePop  = new DPopupList( cmCOD, super, true);
  746.   fCodePop->AddItem("Unknown type");
  747.   fCodePop->AddItem("DNA");
  748.   fCodePop->AddItem("RNA");
  749.   fCodePop->AddItem("Nucleic");
  750.   fCodePop->AddItem("Protein");
  751.   fCodePop->SetValue( fSequence->Kind()+1); // ?? damn this doesn't work 
  752.     //fSequence->SetKind(fCodePop->GetValue()-1); 
  753.  
  754.  
  755.     super= this;
  756.     super->NextSubviewBelowLeft();
  757.     
  758.   clu= new DCluster(0,super,0,0,false,"Selection");
  759.   super= clu;
  760.   pr = new DPrompt(0, super, "start:", 0, 0, gPromptFont, justleft);
  761.   super->NextSubviewToRight();
  762.   fSeqStart = new DPrompt(ctBEG, super, "00000", 0, 0, gPromptFont, justright);
  763.   super->NextSubviewToRight();
  764.  
  765.   pr = new DPrompt(0, super, " end:", 0, 0, gPromptFont, justleft);
  766.   super->NextSubviewToRight();
  767.   fSeqEnd   = new DPrompt(ctEND, super, "00000", 0, 0, gPromptFont, justright);
  768.   super->NextSubviewToRight();
  769.  
  770.   pr = new DPrompt(0, super, " size:", 0, 0, gPromptFont, justleft);
  771.   super->NextSubviewToRight();
  772.   fSeqSel   = new DPrompt(ctSEL, super, "00000", 0, 0, gPromptFont, justright);
  773.       
  774.  
  775.     super= this;
  776.     super->NextSubviewBelowLeft();
  777.      
  778.     fSeqedView= new DSeqedView(cTEVW, super, this, fSequence, 30, 8); // sizes are in SysFontSize...
  779.     fSeqedView->Enable(); //??
  780.     this->SetEditText(fSeqedView);
  781.  
  782.     fFindDlog= new DSeqFindDialog( fSequence, fSeqedView);
  783. }
  784.  
  785. DSeqedWindow::~DSeqedWindow()
  786. {
  787.     // ?? do we need to kill the view components, or does window free do that??
  788. }
  789.  
  790.  
  791. // static
  792. void DSeqedWindow::UpdateEdWinds( DSequence* oldSeq, DSequence* newSeq)
  793. {
  794.     DList* wins= gWindowManager->GetWindowList();
  795.     long i, n= wins->GetSize();
  796.     for (i=0; i<n; i++) {
  797.         DWindow* win= (DWindow*) wins->At(i);
  798.         if (win->Id() == DSeqedWindow::kId) {
  799.             if (((DSeqedWindow*)win)->fSequence == oldSeq) {
  800.                 ((DSeqedWindow*)win)->ReplaceSeq(newSeq);
  801.                 win->Invalidate();
  802.                 }
  803.             }
  804.         }
  805. }
  806.  
  807.                 
  808. #if MAYBE_FIX_LATER
  809. pascal void TSeqedWindow::DoEvent(EventNumber eventNumber, 
  810.                                             TEventHandler        source; TEvent event) // override 
  811. {
  812.     if (eventNumber == mReformatHit) {
  813.         fSequence->Reformat(1);
  814.         fSeqedView->ShowReverted(); //? calls recalc + display?
  815.         }    else
  816.         inherited::DoEvent( eventNumber, source, event);
  817. }
  818. #endif        
  819.  
  820.  
  821. Nlm_Boolean DSeqedWindow::IsMyAction(DTaskMaster* action) 
  822. {    
  823.     long  menuid= 0;
  824.     if (action->fSuperior) menuid = action->fSuperior->Id();
  825.     if (fSeqedView->IsMyAction(action)) 
  826.         return true;
  827.     else if (menuid == DApplication::cEditMenu && HasEditText()) {
  828.         if (fEditText->IsMyAction(action)) ;
  829.         return true;
  830.         }        
  831.     else 
  832.         return DWindow::IsMyAction(action);
  833. }
  834.  
  835.  
  836. void DSeqedWindow::UpdateEdits() 
  837. {
  838.     char    name[128];
  839.     fSeqName->GetTitle( name, 128);
  840.     fSequence->SetName( name);
  841.     
  842.     char* bases= fSeqedView->GetText();
  843.     if (bases) fSequence->SetBases(bases);
  844.     MemFree(bases);
  845.     
  846.     fSequence->UpdateFlds();
  847.     
  848.         //! Need better way than to ForceRedraw of single seq...
  849.     if (fMainDoc) {
  850.         fMainDoc->fAlnView->UpdateWidth(fSequence);
  851.         fMainDoc->fAlnView->Invalidate(); 
  852.         fMainDoc->fAlnIndex->Invalidate();
  853.         }
  854. }
  855.  
  856.  
  857. void DSeqedWindow::Close()  
  858. {
  859.     UpdateEdits();
  860.   DWindow::Close();
  861. }
  862.  
  863.  
  864. void DSeqedWindow::ReplaceSeq(DSequence* aSeq)
  865. {    
  866.     fSequence= aSeq;
  867.     fSeqedView->SetSeq( aSeq);
  868. }
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885. //class DSeqDocPrefs : public DWindow 
  886.  
  887. class DSeqDocPrefs : public DWindow {
  888. public:
  889.     enum { 
  890.             kSeqDocPrefID = 1492,
  891.             kStylePlain,kStyleItalic,kStyleBold,kStyleUnderline,
  892.             cWriteMasks, cStartDoc, cColored
  893.             };
  894.     static char *gSeqFontName;
  895.     static short gSeqFontSize;
  896.     static short gSeqStyle;
  897.     static Boolean gColored;
  898.     static void InitGlobals();
  899.     static void SaveGlobals();
  900.  
  901.     DPopupMenu  * fSeqFontMenu, 
  902.                             * fSeqStyleMenu;
  903.     DSwitchBox    * fSeqSizeSw, * fCommonPctSw;
  904.     Boolean             fNeedSave;
  905.     short                fOldStyle;
  906.     
  907.     DSeqDocPrefs();
  908.     virtual ~DSeqDocPrefs();
  909.     virtual void Initialize();
  910.     virtual void Open();
  911.     virtual void Close();
  912.     virtual void OkayAction();
  913.     virtual Boolean IsMyAction(DTaskMaster* action); 
  914.     virtual void NewFontCluster(char* title, DView* mainview,
  915.                     DPopupMenu*& mfont, DPopupMenu*& mstyle, DSwitchBox*& swsize,
  916.                     char* fontname, short fontstyle, short fontsize );
  917. };
  918.  
  919. Global DSeqDocPrefs* gSeqDocPrefs = NULL;
  920. Global Nlm_FonT gSeqFont = NULL;
  921.  
  922. char* DSeqDocPrefs::gSeqFontName = (char*) "times";
  923. short 
  924.             DSeqDocPrefs::gSeqFontSize = 10, 
  925.             DSeqDocPrefs::gSeqStyle = 0; 
  926. Boolean     
  927.             DSeqDocPrefs::gColored = true;
  928.  
  929. enum FonStyles { 
  930.     kPlain = 0, kItalic = 1, kBold = 2, kUnderline = 4 
  931.     };
  932.  
  933.  
  934. DSeqDocPrefs::DSeqDocPrefs() :
  935.     DWindow( 0, NULL, DWindow::fixed, -10, -10, -50, -20, "SeqDoc prefs", kDontFreeOnClose),
  936.     fSeqFontMenu(NULL), fSeqStyleMenu(NULL), fSeqSizeSw(NULL), fCommonPctSw(NULL),
  937.     fOldStyle(-1), fNeedSave(false)
  938. {    
  939. }
  940.  
  941. DSeqDocPrefs::~DSeqDocPrefs()
  942. {
  943. }
  944.  
  945.  
  946. inline Nlm_FonT GetAFont( char* fname, short fsize, short fstyle)
  947. {
  948.     if (StrICmp(fname,"System")==0) return Nlm_systemFont;
  949.     else if (StrICmp(fname,"Program")==0) return Nlm_programFont;
  950.     else return Nlm_GetFont( fname, fsize, 
  951.              fstyle & kBold, fstyle & kItalic, fstyle & kUnderline, NULL);
  952. }
  953.  
  954. // static
  955. void DSeqDocPrefs::InitGlobals() 
  956.     gSeqFontName= gApplication->GetPref( "gSeqFontName", "fonts", gSeqFontName);
  957.     gSeqFontSize= gApplication->GetPrefVal( "gSeqFontSize", "fonts", "10");
  958.     gSeqStyle= gApplication->GetPrefVal( "gSeqStyle", "fonts", "0");
  959.     gSeqFont= ::GetAFont(gSeqFontName,gSeqFontSize, gSeqStyle);
  960.  
  961.     DSeqFile::gWriteMasks= gApplication->GetPrefVal( "gWriteMasks", "seqdoc", "1");
  962.     DSeqDoc::fgStartDoc    = gApplication->GetPrefVal( "fgStartDoc", "seqdoc", "1");
  963.     DSeqList::gMinCommonPercent= gApplication->GetPrefVal( "gMinCommonPercent", "seqdoc", "70");
  964.     //gColored= gApplication->GetPrefVal( "gColored", "seqdoc","1");
  965. #if 0
  966.     {
  967.     char* srect = gApplication->GetPref( "gSeqPrintDocRect", "windows", "20 20 450 220");
  968.         // sscanf is failing on Mac/codewar !? used to work
  969.     if (srect) {
  970.         char* cp= srect;
  971.         while (*cp && isspace(*cp)) cp++;
  972.         gSeqPrintDocRect.left= atoi( cp);
  973.         
  974.         while (*cp && !isspace(*cp)) cp++;
  975.         while (*cp && isspace(*cp)) cp++;
  976.         gSeqPrintDocRect.top= atoi( cp);
  977.         
  978.         while (*cp && !isspace(*cp)) cp++;
  979.         while (*cp && isspace(*cp)) cp++;
  980.         gSeqPrintDocRect.right= atoi( cp);
  981.         
  982.         while (*cp && !isspace(*cp)) cp++;
  983.         while (*cp && isspace(*cp)) cp++;
  984.         gSeqPrintDocRect.bottom= atoi( cp);
  985.         }
  986.     MemFree(srect);
  987.     }    
  988. #endif
  989.  
  990. }
  991.  
  992.  
  993. //static
  994. void DSeqDocPrefs::SaveGlobals() 
  995. {
  996.     gApplication->SetPref( gSeqFontName, "gSeqFontName", "fonts");
  997.     gApplication->SetPref( gSeqFontSize, "gSeqFontSize", "fonts");
  998.     gApplication->SetPref( gSeqStyle, "gSeqStyle", "fonts");
  999.     
  1000.     //gApplication->SetPref( gColored, "gColored", "seqdoc");
  1001.     gApplication->SetPref(  DSeqFile::gWriteMasks, "gWriteMasks", "seqdoc");
  1002.     gApplication->SetPref(  DSeqDoc::fgStartDoc, "fgStartDoc", "seqdoc");
  1003.     gApplication->SetPref(  DSeqList::gMinCommonPercent, "gMinCommonPercent", "seqdoc");
  1004. }
  1005.  
  1006.  
  1007.  
  1008.  
  1009. void DSeqDocPrefs::NewFontCluster(char* title, DView* mainview,
  1010.                     DPopupMenu*& mfont, DPopupMenu*& mstyle, DSwitchBox*& swsize,
  1011.                     char* fontname, short fontstyle, short fontsize )
  1012. {    
  1013.         // Name style -- font, font size, font style
  1014.     DPopupMenu* popm;
  1015.     DSwitchBox* sw;
  1016.     DPrompt* pr;
  1017.     DView* super;
  1018.     
  1019.     super= mainview;
  1020.     super->NextSubviewBelowLeft();
  1021.  
  1022.     DCluster* maincluster= new DCluster( 0, super, 50, 10, true, NULL); //false, title);
  1023.     super= maincluster;
  1024.  
  1025.     popm= new DPopupMenu( 0, (Nlm_GrouP)super->GetNlmObject(), "Font  ");
  1026.     mfont= popm;
  1027.     popm->AddFonts();
  1028.     popm->SetFontChoice( fontname); 
  1029.     //super->NextSubviewToRight();
  1030.  
  1031. #if 0
  1032.     DPopupList* popl;
  1033.     popl= new DPopupList( 0,super,true);
  1034.     mstyle= (DPopupMenu*) popl;
  1035.     popl->AddItem("Plain");
  1036.     popl->AddItem("Italic");
  1037.     popl->AddItem("Bold");
  1038.     popl->AddItem( "Underline");
  1039. #else
  1040.     popm= new DPopupMenu( 0, (Nlm_GrouP)super->GetNlmObject(), "Style  ");
  1041.     mstyle= popm;
  1042.     popm->AddItem( kStylePlain, "Plain", true);
  1043.     popm->AddItem( kStyleItalic, "Italic", true);
  1044.     popm->AddItem( kStyleBold, "Bold", true);
  1045.     popm->AddItem( kStyleUnderline, "Underline", true);
  1046.     popm->SetItemStatus( kStylePlain, fontstyle==0);
  1047.     popm->SetItemStatus( kStyleItalic, fontstyle & kItalic);
  1048.     popm->SetItemStatus( kStyleBold, fontstyle & kBold);
  1049.     popm->SetItemStatus( kStyleUnderline, fontstyle & kUnderline);
  1050. #endif
  1051.     //super->NextSubviewToRight();
  1052.     
  1053.     DCluster* cluster= new DCluster(0, super, 30, 10, true, NULL);
  1054.     super= cluster;
  1055.     
  1056.     pr= new DPrompt( 0, super, "font size", 0, 0, Nlm_programFont);             
  1057.     //super->NextSubviewToRight();
  1058.     super->NextSubviewBelowLeft();
  1059.     sw = new DSwitchBox(0, super, true, true);
  1060.     swsize= sw;
  1061.     sw->SetValues(fontsize,99);
  1062.     //super->NextSubviewBelowLeft();
  1063.  
  1064.     super= mainview;
  1065.     super->NextSubviewBelowLeft();
  1066. }
  1067.  
  1068.  
  1069. void DSeqDocPrefs::Initialize() 
  1070.     DView* super;
  1071.     DCluster* clu;
  1072.     DCheckBox* ck;
  1073.  
  1074.     super= this;
  1075.     clu= new DCluster( 0, super, 80, 10, false, "Sequence");
  1076.     super= clu;
  1077.  
  1078.     NewFontCluster( "Seq font style", super, fSeqFontMenu, fSeqStyleMenu, fSeqSizeSw,
  1079.                             gSeqFontName, gSeqStyle, gSeqFontSize);
  1080.   fOldStyle= gSeqStyle;
  1081.  
  1082.     super= this;
  1083.     ck= new DCheckBox(cWriteMasks, super, "Save masks in file");
  1084.     ck->SetStatus(DSeqFile::gWriteMasks);
  1085.     super->NextSubviewBelowLeft();
  1086.  
  1087.     // check box for auto new document on startup ??
  1088.     ck= new DCheckBox(cStartDoc, super, "New align document on startup");
  1089.     ck->SetStatus(DSeqDoc::fgStartDoc);
  1090.     super->NextSubviewBelowLeft();
  1091.  
  1092.     new DPrompt( 0, super, "% common bases for consensus", 0, 0, Nlm_programFont);             
  1093.     super->NextSubviewToRight();
  1094.     fCommonPctSw = new DSwitchBox(0, super, true, true);
  1095.     fCommonPctSw->SetValues(DSeqList::gMinCommonPercent,100);
  1096.     super->NextSubviewBelowLeft();
  1097.     
  1098.     //ck= new DCheckBox(cColored, super, "Colored bases");
  1099.     //ck->SetStatus(gColored);
  1100.  
  1101.     super = this;
  1102.     //super->NextSubviewToRight();
  1103.     //super->NextSubviewBelowLeft();
  1104.  
  1105.     this->AddOkayCancelButtons();
  1106. }
  1107.  
  1108.  
  1109. void DSeqDocPrefs::OkayAction() 
  1110.     short             aSize, aStyle, aCommon;
  1111.     char            name[256];
  1112.     DMenu     *    aFontMenu, * aStyleMenu;
  1113.     Nlm_FonT    aFont;
  1114.     Boolean   newstyle;
  1115.     
  1116.     for (short imenu= 0; imenu<1; imenu++) {
  1117.         
  1118.         switch (imenu) {
  1119.           case 0:
  1120.                 aFontMenu= fSeqFontMenu; 
  1121.                 aStyleMenu= fSeqStyleMenu; 
  1122.                 aSize= fSeqSizeSw->GetValue();// aSize= gNameFontSize;
  1123.                  
  1124.                 aCommon= fCommonPctSw->GetValue();
  1125.                 if (aCommon != DSeqList::gMinCommonPercent) {                
  1126.                     DSeqList::gMinCommonPercent= aCommon;
  1127.                     fNeedSave= true;
  1128.                     }
  1129.               break;
  1130.           }
  1131.             
  1132.         if (aFontMenu && aFontMenu->GetFontChoice(name, sizeof(name))) {
  1133.         
  1134.             aStyle= 0;
  1135. #ifdef WIN_MAC
  1136.             if (!aStyleMenu->GetItemStatus(kStylePlain)) {
  1137.                 if (aStyleMenu->GetItemStatus(kStyleItalic   )) aStyle |= kItalic;
  1138.                 if (aStyleMenu->GetItemStatus(kStyleBold     )) aStyle |= kBold;
  1139.                 if (aStyleMenu->GetItemStatus(kStyleUnderline)) aStyle |= kUnderline;
  1140.                 }
  1141. #else
  1142.             short item= Nlm_GetValue(((DPopupMenu*)aStyleMenu)->fPopup);
  1143.             switch (item) {
  1144.                 case 1: aStyle= 0; break;
  1145.                 case 2: aStyle |= kItalic; break;
  1146.                 case 3: aStyle |= kBold; break;
  1147.                 case 4: aStyle |= kUnderline; break;
  1148.         }
  1149. #endif
  1150.              newstyle= aStyle != gSeqStyle;
  1151.              
  1152.             if (StringCmp(name,"System")==0) aFont= Nlm_systemFont;
  1153.             else if (StringCmp(name,"Program")==0) aFont= Nlm_programFont;
  1154.             else aFont= Nlm_GetFont( name, aSize, aStyle & kBold, aStyle & kItalic, 
  1155.                                                              aStyle & kUnderline, NULL);
  1156.             switch (imenu) {
  1157.               case 0: 
  1158.               if (newstyle || aSize != gSeqFontSize || StringCmp(name,gSeqFontName)!=0) {
  1159.                     if (gSeqFontName) MemFree(gSeqFontName);
  1160.                     gSeqFontName= StrDup(name);
  1161.                     gSeqFont= aFont;
  1162.                     gSeqFontSize= aSize;
  1163.                     gSeqStyle= aStyle;
  1164.                     fNeedSave= true;
  1165.                     }
  1166.                   break;
  1167.               }
  1168.               
  1169.             }
  1170.         }
  1171. }
  1172.  
  1173.  
  1174.  
  1175. Boolean DSeqDocPrefs::IsMyAction(DTaskMaster* action) 
  1176. {    
  1177.     DView* aview= (DView*) action;
  1178.     
  1179.     switch (action->Id()) {
  1180.             // ?? handle stylemenu popup -- if plain selected, deselect others...
  1181.         //case kSeqStyleMenu:     break;
  1182.         //case cColored    : gColored= aview->GetStatus(); break;
  1183.         case cWriteMasks: DSeqFile::gWriteMasks= aview->GetStatus(); break;
  1184.         case cStartDoc  : DSeqDoc::fgStartDoc= aview->GetStatus(); break;
  1185.         default : return DWindow::IsMyAction(action);    
  1186.         }
  1187.         
  1188.     fNeedSave= true;
  1189.     return true;
  1190. }
  1191.  
  1192.  
  1193. void DSeqDocPrefs::Open()
  1194. {
  1195.     DWindow::Open();
  1196. }
  1197.  
  1198. void DSeqDocPrefs::Close()
  1199. {
  1200.     if (fNeedSave) {
  1201.         DSeqDocPrefs::SaveGlobals();
  1202.         fNeedSave= false;
  1203.         }
  1204.     DWindow::Close();
  1205. }
  1206.  
  1207.  
  1208.  
  1209.     // global calling function
  1210. void SeqDocPrefs(short id)
  1211. {
  1212.     switch (id) {
  1213.         case kSeqDocPrefInit: 
  1214.             DSeqDocPrefs::InitGlobals(); 
  1215.             break;
  1216.     
  1217.         case kSeqDocPrefDialog:
  1218.             if (!gSeqDocPrefs) {
  1219.                 gSeqDocPrefs = new DSeqDocPrefs();
  1220.                 gSeqDocPrefs->Initialize();
  1221.                 }
  1222.             if (gSeqDocPrefs && gSeqDocPrefs->PoseModally()) ;
  1223.             break;
  1224.     }
  1225.     
  1226. }
  1227.  
  1228.  
  1229.  
  1230. #if NETBLAST
  1231.  
  1232. ///class DBlastDialog : public DWindow 
  1233.  
  1234. class DBlastDialog : public DWindow {
  1235. public:
  1236.     enum { 
  1237.             kBlastDialogID = 29852,
  1238.             kStylePlain,kStyleItalic,kStyleBold,kStyleUnderline,
  1239.             cWriteMasks, cStartDoc, cColored
  1240.             };
  1241.     static char *gSeqFontName;
  1242.     static short gSeqFontSize;
  1243.     static short gSeqStyle;
  1244.     static Boolean gColored;
  1245.     static void InitGlobals();
  1246.     static void SaveGlobals();
  1247.  
  1248.     DPopupMenu  * fBlastDataMenu, 
  1249.                             * fBlastProgMenu;
  1250.     DSwitchBox    * fSeqSizeSw, * fCommonPctSw;
  1251.     Boolean             fNeedSave;
  1252.     short                fOldStyle;
  1253.     
  1254.     DBlastDialog();
  1255.     virtual ~DBlastDialog();
  1256.     virtual void Initialize();
  1257.     virtual void Open();
  1258.     virtual void Close();
  1259.     virtual void OkayAction();
  1260.     virtual Boolean IsMyAction(DTaskMaster* action); 
  1261.     virtual void NewFontCluster(char* title, DView* mainview,
  1262.                     DPopupMenu*& mfont, DPopupMenu*& mstyle, DSwitchBox*& swsize,
  1263.                     char* fontname, short fontstyle, short fontsize );
  1264. };
  1265.  
  1266. Global DBlastDialog* gSeqDocPrefs = NULL;
  1267. Global Nlm_FonT gSeqFont = NULL;
  1268.  
  1269. char* DBlastDialog::gSeqFontName = (char*) "times";
  1270. short 
  1271.             DBlastDialog::gSeqFontSize = 10, 
  1272.             DBlastDialog::gSeqStyle = 0; 
  1273. Boolean     
  1274.             DBlastDialog::gColored = true;
  1275.  
  1276. enum FonStyles { 
  1277.     kPlain = 0, kItalic = 1, kBold = 2, kUnderline = 4 
  1278.     };
  1279.  
  1280.  
  1281. DBlastDialog::DBlastDialog() :
  1282.     DWindow( 0, NULL, DWindow::fixed, -10, -10, -50, -20, "SeqDoc prefs", kDontFreeOnClose),
  1283.     fSeqFontMenu(NULL), fSeqStyleMenu(NULL), fSeqSizeSw(NULL), fCommonPctSw(NULL),
  1284.     fOldStyle(-1), fNeedSave(false)
  1285. {    
  1286. }
  1287.  
  1288. DBlastDialog::~DBlastDialog()
  1289. {
  1290. }
  1291.  
  1292.  
  1293. // static
  1294. void DBlastDialog::InitGlobals() 
  1295.     gSeqFontName= gApplication->GetPref( "gSeqFontName", "fonts", gSeqFontName);
  1296.     gSeqFontSize= gApplication->GetPrefVal( "gSeqFontSize", "fonts", "10");
  1297.     gSeqStyle= gApplication->GetPrefVal( "gSeqStyle", "fonts", "0");
  1298.     gSeqFont= ::GetAFont(gSeqFontName,gSeqFontSize, gSeqStyle);
  1299.  
  1300.     DSeqFile::gWriteMasks= gApplication->GetPrefVal( "gWriteMasks", "seqdoc", "1");
  1301.     DSeqDoc::fgStartDoc    = gApplication->GetPrefVal( "fgStartDoc", "seqdoc", "1");
  1302.     DSeqList::gMinCommonPercent= gApplication->GetPrefVal( "gMinCommonPercent", "seqdoc", "70");
  1303.     //gColored= gApplication->GetPrefVal( "gColored", "seqdoc","1");
  1304.  
  1305. }
  1306.  
  1307.  
  1308. //static
  1309. void DBlastDialog::SaveGlobals() 
  1310. {
  1311.     gApplication->SetPref( gSeqFontName, "gSeqFontName", "fonts");
  1312.     gApplication->SetPref( gSeqFontSize, "gSeqFontSize", "fonts");
  1313.     gApplication->SetPref( gSeqStyle, "gSeqStyle", "fonts");
  1314.     
  1315.     //gApplication->SetPref( gColored, "gColored", "seqdoc");
  1316.     gApplication->SetPref(  DSeqFile::gWriteMasks, "gWriteMasks", "seqdoc");
  1317.     gApplication->SetPref(  DSeqDoc::fgStartDoc, "fgStartDoc", "seqdoc");
  1318.     gApplication->SetPref(  DSeqList::gMinCommonPercent, "gMinCommonPercent", "seqdoc");
  1319. }
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325. void DBlastDialog::Initialize() 
  1326.     DView* super;
  1327.     DCluster* clu;
  1328.     DCheckBox* ck;
  1329.  
  1330.     char* blastProgram = "blastn";
  1331.     char* blastDatabase = "nr";
  1332.     char* blastOptions = NULL;
  1333.     char* fastaInputFile = "spup-blast-input.fasta";
  1334.     char* outputFile = "spup-blast-result.text";
  1335.  
  1336.     super= this;
  1337.     
  1338.     new DPrompt( 0, super, "BLAST program", 0, 0, Nlm_programFont);             
  1339.     super->NextSubviewToRight();
  1340.         // fBlastProgMenu needs to be configurable from table file/prefs file
  1341.     fBlastProgMenu= new DPopupList( cBlastProg, super, true);
  1342.     super->NextSubviewBelowLeft();
  1343.     if (fSeq->IsAmino() {
  1344.           // protein query seq
  1345.       fBlastProgMenu->AddItem("blastp");
  1346.       fBlastProgMenu->AddItem("tblastn");
  1347.         }
  1348.     else {
  1349.             // nucleic query seq
  1350.       fBlastProgMenu->AddItem("blastn");
  1351.       fBlastProgMenu->AddItem("blastx");
  1352.       fBlastProgMenu->AddItem("tblastx");
  1353.       }
  1354.   fBlastProgMenu->SetValue(1); 
  1355.  
  1356.  
  1357.     new DPrompt( 0, super, "Nucleic databanks", 0, 0, Nlm_programFont);             
  1358.     super->NextSubviewToRight();
  1359.         // fDataMenu needs to be configurable from table file/prefs file
  1360.     fNucDataMenu= new DPopupList( cNucData, super, true);
  1361.     super->NextSubviewBelowLeft();
  1362.  
  1363.   fNucDataMenu->AddItem("nr");
  1364.   fNucDataMenu->AddItem("genbank");   
  1365.   fNucDataMenu->AddItem("gbupdate");  
  1366.   fNucDataMenu->AddItem("embl");  
  1367.   fNucDataMenu->AddItem("emblu");   
  1368.   fNucDataMenu->AddItem("pdb");  
  1369.   fNucDataMenu->AddItem("vector");  
  1370.   fNucDataMenu->AddItem("vector2");  
  1371.   fNucDataMenu->AddItem("dbest");  
  1372.   fNucDataMenu->AddItem("dbsts");  
  1373.   fNucDataMenu->AddItem("epd");  
  1374.   fNucDataMenu->AddItem("kabat");  
  1375.   fNucDataMenu->AddItem("hspest");  
  1376.   fNucDataMenu->AddSeparator();  
  1377.   fNucDataMenu->SetValue(1); 
  1378.  
  1379.     new DPrompt( 0, super, "Amino-acid databanks", 0, 0, Nlm_programFont);             
  1380.     super->NextSubviewToRight();
  1381.         // fDataMenu needs to be configurable from table file/prefs file
  1382.     fAminoDataMenu= new DPopupList( cAminoData, super, true);
  1383.     super->NextSubviewBelowLeft();
  1384.  
  1385.   fAminoDataMenu->AddItem("nr");
  1386.   fAminoDataMenu->AddItem("pdb");  
  1387.   fAminoDataMenu->AddItem("swissprot");  
  1388.   fAminoDataMenu->AddItem("spupdate");  
  1389.   fAminoDataMenu->AddItem("pir");  
  1390.   fAminoDataMenu->AddItem("genbank");  
  1391.   fAminoDataMenu->AddItem("gpupdate");  
  1392.   fAminoDataMenu->AddItem("tfd");  
  1393.   fAminoDataMenu->AddItem("kabat");  
  1394.   fAminoDataMenu->AddItem("hspnr");  
  1395.   fAminoDataMenu->AddItem("hspspdb");  
  1396.      
  1397.   fAminoDataMenu->SetValue(1); 
  1398.  
  1399. //////////////////////////////
  1400.     super= this;
  1401.     ck= new DCheckBox(cWriteMasks, super, "Save masks in file");
  1402.     ck->SetStatus(DSeqFile::gWriteMasks);
  1403.     super->NextSubviewBelowLeft();
  1404.  
  1405.     // check box for auto new document on startup ??
  1406.     ck= new DCheckBox(cStartDoc, super, "New align document on startup");
  1407.     ck->SetStatus(DSeqDoc::fgStartDoc);
  1408.     super->NextSubviewBelowLeft();
  1409.  
  1410.     new DPrompt( 0, super, "% common bases for consensus", 0, 0, Nlm_programFont);             
  1411.     super->NextSubviewToRight();
  1412.     fCommonPctSw = new DSwitchBox(0, super, true, true);
  1413.     fCommonPctSw->SetValues(DSeqList::gMinCommonPercent,100);
  1414.     super->NextSubviewBelowLeft();
  1415.     
  1416.     //ck= new DCheckBox(cColored, super, "Colored bases");
  1417.     //ck->SetStatus(gColored);
  1418.  
  1419.     super = this;
  1420.     //super->NextSubviewToRight();
  1421.     //super->NextSubviewBelowLeft();
  1422.  
  1423.     this->AddOkayCancelButtons();
  1424. }
  1425.  
  1426.  
  1427. void DBlastDialog::OkayAction() 
  1428.     short             aSize, aStyle, aCommon;
  1429.     char            name[256];
  1430.     DMenu     *    aFontMenu, * aStyleMenu;
  1431.     Nlm_FonT    aFont;
  1432.     Boolean   newstyle;
  1433.     
  1434.     for (short imenu= 0; imenu<1; imenu++) {
  1435.         
  1436.         switch (imenu) {
  1437.           case 0:
  1438.                 aFontMenu= fSeqFontMenu; 
  1439.                 aStyleMenu= fSeqStyleMenu; 
  1440.                 aSize= fSeqSizeSw->GetValue();// aSize= gNameFontSize;
  1441.                  
  1442.                 aCommon= fCommonPctSw->GetValue();
  1443.                 if (aCommon != DSeqList::gMinCommonPercent) {                
  1444.                     DSeqList::gMinCommonPercent= aCommon;
  1445.                     fNeedSave= true;
  1446.                     }
  1447.               break;
  1448.           }
  1449.             
  1450.         if (aFontMenu && aFontMenu->GetFontChoice(name, sizeof(name))) {
  1451.         
  1452.             aStyle= 0;
  1453.  
  1454.             short item= Nlm_GetValue(((DPopupMenu*)aStyleMenu)->fPopup);
  1455.             switch (item) {
  1456.                 case 1: aStyle= 0; break;
  1457.                 case 2: aStyle |= kItalic; break;
  1458.                 case 3: aStyle |= kBold; break;
  1459.                 case 4: aStyle |= kUnderline; break;
  1460.         }
  1461.              newstyle= aStyle != gSeqStyle;
  1462.              
  1463.             if (StringCmp(name,"System")==0) aFont= Nlm_systemFont;
  1464.             else if (StringCmp(name,"Program")==0) aFont= Nlm_programFont;
  1465.             else aFont= Nlm_GetFont( name, aSize, aStyle & kBold, aStyle & kItalic, 
  1466.                                                              aStyle & kUnderline, NULL);
  1467.             switch (imenu) {
  1468.               case 0: 
  1469.               if (newstyle || aSize != gSeqFontSize || StringCmp(name,gSeqFontName)!=0) {
  1470.                     if (gSeqFontName) MemFree(gSeqFontName);
  1471.                     gSeqFontName= StrDup(name);
  1472.                     gSeqFont= aFont;
  1473.                     gSeqFontSize= aSize;
  1474.                     gSeqStyle= aStyle;
  1475.                     fNeedSave= true;
  1476.                     }
  1477.                   break;
  1478.               }
  1479.               
  1480.             }
  1481.         }
  1482. }
  1483.  
  1484.  
  1485.  
  1486. Boolean DBlastDialog::IsMyAction(DTaskMaster* action) 
  1487. {    
  1488.     DView* aview= (DView*) action;
  1489.     
  1490.     switch (action->Id()) {
  1491.         //case cWriteMasks: DSeqFile::gWriteMasks= aview->GetStatus(); break;
  1492.         //case cStartDoc  : DSeqDoc::fgStartDoc= aview->GetStatus(); break;
  1493.         default : return DWindow::IsMyAction(action);    
  1494.         }
  1495.         
  1496.     fNeedSave= true;
  1497.     return true;
  1498. }
  1499.  
  1500.  
  1501. void DBlastDialog::Open()
  1502. {
  1503.     DWindow::Open();
  1504. }
  1505.  
  1506. void DBlastDialog::Close()
  1507. {
  1508.     if (fNeedSave) {
  1509.         DBlastDialog::SaveGlobals();
  1510.         fNeedSave= false;
  1511.         }
  1512.     DWindow::Close();
  1513. }
  1514.  
  1515.  
  1516.         
  1517. #endif
  1518.