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

  1. // DFindDlog.cpp
  2.  
  3.  
  4. #include <ncbi.h>
  5. #include <dgg.h>
  6. #include <Dvibrant.h>
  7. #include <DControl.h>
  8. #include <DDialogText.h>
  9. #include <DApplication.h>
  10. #include <DMenu.h>
  11. #include <DWindow.h>
  12. #include <DTask.h>
  13. #include "DFindDlog.h"
  14.  
  15.  
  16. Boolean DFindDialog::fBackwards= false;
  17. Boolean DFindDialog::fCaseSense= false;
  18. Boolean DFindDialog::fFullWord= false;
  19. char* DFindDialog::fTarget[DFindDialog::kMaxTarg];
  20. char* DFindDialog::fReplace[DFindDialog::kMaxReplace];
  21.  
  22.  
  23. void DFindDialog::FindAgain()
  24. {
  25.     DoFind();
  26. }
  27.  
  28. Boolean DFindDialog::IsMyAction(DTaskMaster* action) 
  29. {    
  30.     DView* aview= (DView*) action;
  31.  
  32.     switch (action->Id()) {
  33.         case cBackwards : fBackwards= aview->GetStatus(); return true;
  34.         case cCaseSense : fCaseSense= aview->GetStatus(); return true;
  35.         case cFullWord  : fFullWord= aview->GetStatus(); return true;
  36.  
  37.         case findId:
  38.         case replaceId:
  39.         case replaceFindId:
  40.         case replaceAllId:
  41.             switch (action->Id()) {
  42.                 case replaceFindId: 
  43.                     GetReplace(); DoReplace(); 
  44.                     // fall into findId
  45.                 case findId        : 
  46.                     GetFind(); DoFind();     
  47.                     break;
  48.                     
  49.                 case replaceId: 
  50.                     GetReplace(); DoReplace(); 
  51.                     break;
  52.                     
  53.                 case replaceAllId: 
  54.                     GetReplace(); DoReplaceAll(); 
  55.                     break;
  56.                 }
  57.             fModal= false;
  58.             this->Close(); 
  59.             return true;
  60.             
  61.         default:
  62.             return DWindow::IsMyAction(action);    
  63.         }
  64. }
  65.  
  66.  
  67. DFindDialog::DFindDialog() :
  68.   DWindow( 0, gApplication, DWindow::fixed, -10, -10, -50, -20, "Find", kDontFreeOnClose) 
  69.     //fBackwards(false), fCaseSense(false), fFullWord(false)
  70. {
  71.     fFindText= NULL;
  72.     fReplaceText= NULL;
  73. #if 0
  74.     short i;
  75.     for (i=0; i<kMaxTarg; i++) fTarget[i] = NULL;
  76.     for (i=0; i<kMaxReplace; i++) fReplace[i] = NULL;
  77. #endif
  78. }
  79.  
  80. void DFindDialog::Open()
  81. {
  82.     if (!fFindText) BuildDlog();     
  83.     this->Select(); // for motif
  84.     DWindow::Open();
  85. }
  86.  
  87. void DFindDialog::InitFindDialog()
  88. {
  89.     short i;
  90.     fBackwards= false;
  91.     fCaseSense= false;
  92.     fFullWord= false;
  93.     for (i=0; i<kMaxTarg; i++) fTarget[i] = NULL;
  94.     for (i=0; i<kMaxReplace; i++) fReplace[i] = NULL;
  95. }
  96.  
  97. const char* DFindDialog::GetReplace()
  98. {
  99.     if (fReplaceText) {
  100.         char* str= fReplaceText->GetText();
  101.         Boolean gotstr= (str && *str);
  102.         if (gotstr && (!fReplace[0] || StringCmp( str, fReplace[0]) != 0)) {
  103.             MemFree(fReplace[kMaxReplace-1]);
  104.             for (short i=kMaxReplace-1; i>0; i--) fReplace[i] = fReplace[i-1];
  105.             fReplace[0]= str;
  106.             }
  107.         else
  108.             MemFree( str);
  109.         return fReplace[0];
  110.         }
  111.     else return NULL;
  112. }
  113.  
  114. const char* DFindDialog::GetFind()
  115. {
  116.     if (fFindText) {
  117.         char* str= fFindText->GetText();
  118.         Boolean gotstr= (str && *str);
  119.         if (gotstr && (!fTarget[0] || StringCmp( str, fTarget[0]) != 0)) {
  120.             MemFree(fTarget[kMaxTarg-1]);
  121.             for (short i=kMaxTarg-1; i>0; i--) fTarget[i] = fTarget[i-1];
  122.             fTarget[0]= str;
  123.             }
  124.         else
  125.             MemFree( str);
  126.         return fTarget[0];
  127.         }
  128.     else return NULL;
  129. }
  130.     
  131.  
  132. DFindDialog::~DFindDialog()
  133. {
  134. #if 0
  135.     short i;
  136.     for (i=0; i<kMaxTarg; i++) MemFree(fTarget[i]);
  137.     for (i=0; i<kMaxReplace; i++) MemFree(fReplace[i]);
  138. #endif
  139. }
  140.  
  141.  
  142. void DFindDialog::BuildDlog()
  143. {
  144.     DView * super;
  145.     DPrompt* pr;
  146.     DCheckBox* ck;
  147.     DCluster * maincluster;
  148.     DDefaultButton* db;
  149.     DButton* bb;
  150.     char    * target;
  151.     Nlm_PoinT npt;
  152.     
  153.     super= this;
  154.  
  155. #if 0    
  156.         // this cluster messes up location of DEditText....
  157.     maincluster= new DCluster( 0, super, 60, 40, true, NULL); 
  158.     super= maincluster;
  159. #endif
  160.  
  161.     pr= new DPrompt( 0, super, "   Find", 0, 0, Nlm_programFont);             
  162.     super->NextSubviewToRight();
  163.     target= fTarget[0];
  164.     fFindText= new DEditText( 0, super, target, 50, Nlm_programFont); 
  165.     this->SetEditText( fFindText);
  166.  
  167.     super->NextSubviewBelowLeft();
  168.     pr= new DPrompt( 0, super, "Replace", 0, 0, Nlm_programFont);             
  169.     super->NextSubviewToRight();
  170.     target= fReplace[0];
  171.     fReplaceText= new DEditText( 0, super, target, 50, Nlm_programFont); 
  172.  
  173.  
  174.     maincluster= new DCluster( 0, super, 60, 10, true, NULL); 
  175.     super= maincluster;
  176.  
  177.     super->NextSubviewBelowLeft();
  178.     ck= new DCheckBox(cBackwards, super, "Backwards");
  179.     ck->SetStatus(fBackwards);
  180.     super->NextSubviewToRight();
  181.     ck= new DCheckBox(cCaseSense, super, "Case sensitive");
  182.     ck->SetStatus(fCaseSense);
  183.     super->NextSubviewToRight();
  184.     ck= new DCheckBox(cFullWord, super, "Entire word");
  185.     ck->SetStatus(fFullWord);
  186.     //super->NextSubviewToRight();
  187.  
  188.     super= this;
  189.     //super->NextSubviewToRight();
  190.     super->NextSubviewBelowLeft();
  191.  
  192. #if 1
  193.     maincluster= new DCluster( 0, super, 10, 40, true, NULL); 
  194.     super= maincluster;
  195. #endif
  196.  
  197.     bb= new DButton( replaceId, super, "Replace");
  198.     super->NextSubviewToRight();
  199.     bb= new DButton( replaceFindId, super, "Replace & Find");
  200.     super->NextSubviewToRight();
  201.     bb= new DButton( replaceAllId, super, "Replace All");
  202.     super->NextSubviewToRight();
  203.      super->GetNextPosition( &npt);
  204.      npt.x += 8;   
  205.      super->SetNextPosition( npt);
  206.     db= new DDefaultButton( findId, super, "Find");
  207.     //db->SetResize( DView::fixed, DView::moveinsuper); 
  208.  
  209.     super = this;
  210. }
  211.     
  212.  
  213.  
  214.