home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / TimGA 1.2.1 / .cp / CEvalDialog.cp < prev    next >
Encoding:
Text File  |  1997-07-16  |  5.4 KB  |  195 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CEvalDialog.cp        ©1995-97 Timo Eloranta        All rights reserved.
  3. // ===========================================================================
  4.  
  5. #include "CEvalDialog.h"
  6. #include "GraphGA_PaneIDs.h"
  7.  
  8. #include <LGAEditField.h>
  9. #include <LGAPushButton.h>
  10. #include <LGACheckbox.h>
  11.  
  12. #include <PP_Messages.h>
  13. #include <UReanimator.h>
  14. #include <UDesktop.h>
  15.  
  16. // ---------------------------------------------------------------------------
  17. //        • CEvalDialog
  18. //
  19. //          Called by:    URegistrar::CreateObject
  20. // ---------------------------------------------------------------------------
  21.  
  22. CEvalDialog::CEvalDialog( LStream *inStream )
  23.     : LGADialogBox( inStream )
  24. {
  25. }
  26.  
  27. // ---------------------------------------------------------------------------
  28. //        • InitDialog
  29. //
  30. //          Called by:    CGraphGAApp::ObeyCommand
  31. // ---------------------------------------------------------------------------
  32.  
  33. void
  34. CEvalDialog::InitDialog()
  35. {
  36.     mFactoryButton    = (LGAPushButton *) this -> FindPaneByID( but_FactorySettings );
  37.         
  38.     mCrossingsBox    = (LGACheckbox *) this -> FindPaneByID( cbox_CrossingsRule );
  39.  
  40.     UReanimator::LinkListenerToControls( this, this, WIND_Evaluate );
  41.  
  42.     mEdit1            = (LGAEditField *) this -> FindPaneByID( edit_1 );
  43.     mEdit2            = (LGAEditField *) this -> FindPaneByID( edit_2 );
  44.     mEdit3            = (LGAEditField *) this -> FindPaneByID( edit_3 );
  45.     mEdit4            = (LGAEditField *) this -> FindPaneByID( edit_4 );
  46.     mEdit5            = (LGAEditField *) this -> FindPaneByID( edit_5 );
  47.     mEdit6            = (LGAEditField *) this -> FindPaneByID( edit_6 );
  48.     mEdit7            = (LGAEditField *) this -> FindPaneByID( edit_7 );
  49. }
  50.  
  51. // ---------------------------------------------------------------------------
  52. //        • SetValues
  53. //
  54. //          Called by:    CGraphGAApp::ObeyCommand
  55. // ---------------------------------------------------------------------------
  56.  
  57. void
  58. CEvalDialog::SetValues( SEvaluation &inEval )
  59. {
  60.     mCrossingsBox ->    SetValue( inEval.crossingsRule );
  61.  
  62.     mEdit1 ->            SetValue( inEval.multip1 );
  63.     mEdit2 ->            SetValue( inEval.multip2 );
  64.     mEdit3 ->            SetValue( inEval.multip3 );
  65.     mEdit4 ->            SetValue( inEval.multip4 );
  66.     mEdit5 ->            SetValue( inEval.multip5 );
  67.     mEdit6 ->            SetValue( inEval.multip6 );
  68.     mEdit7 ->            SetValue( inEval.multip7 );
  69.  
  70.     mEdit1 -> SelectAll();
  71.     SetLatentSub( mEdit1 );
  72.         
  73.     AdjustFactoryButton();
  74. }
  75.  
  76. // ---------------------------------------------------------------------------
  77. //        • SetDefaultValues    (PRIVATE)
  78. //
  79. //          Called by:    CEvalDialog::ListenToMessage
  80. // ---------------------------------------------------------------------------
  81.  
  82. void
  83. CEvalDialog::SetDefaultValues( )
  84. {
  85.     mCrossingsBox ->    SetValue( DEFAULT_CROSSINGS_RULE );
  86.  
  87.     mEdit1 ->            SetValue( DEFAULT_MULTIP_1 );
  88.     mEdit2 ->            SetValue( DEFAULT_MULTIP_2 );
  89.     mEdit3 ->            SetValue( DEFAULT_MULTIP_3 );
  90.     mEdit4 ->            SetValue( DEFAULT_MULTIP_4 );
  91.     mEdit5 ->            SetValue( DEFAULT_MULTIP_5 );
  92.     mEdit6 ->            SetValue( DEFAULT_MULTIP_6 );
  93.     mEdit7 ->            SetValue( DEFAULT_MULTIP_7 );
  94. }
  95.  
  96. // ---------------------------------------------------------------------------
  97. //        • GetValues
  98. //
  99. //          Called by:    CGraphGAApp::SetEvalFromDialog
  100. // ---------------------------------------------------------------------------
  101.  
  102. void
  103. CEvalDialog::GetValues( SEvaluation &outEval )
  104. {
  105.     Boolean        theZeros = false;
  106.     Int16        theTemp;
  107.  
  108.     outEval.crossingsRule    = mCrossingsBox ->    GetValue();
  109.  
  110.     outEval.multip1        = mEdit1 ->     GetValue();
  111.     outEval.multip2        = mEdit2 ->     GetValue();
  112.     outEval.multip3        = mEdit3 ->     GetValue();
  113.     outEval.multip6        = mEdit6 ->     GetValue();
  114.     
  115.     theTemp = mEdit4 ->     GetValue();
  116.     if ( theTemp ) outEval.multip4 = theTemp; 
  117.         else theZeros = true;
  118.  
  119.     theTemp = mEdit5 ->     GetValue();
  120.     if ( theTemp ) outEval.multip5 = theTemp; 
  121.         else theZeros = true;
  122.  
  123.     theTemp = mEdit7 ->     GetValue();
  124.     if ( theTemp ) outEval.multip7 = theTemp; 
  125.         else theZeros = true;
  126.  
  127.     if ( theZeros ) {
  128.         UDesktop::Deactivate();
  129.         ::StopAlert( ALRT_DivideByZero, nil );
  130.         UDesktop::Activate();
  131.     }
  132. }
  133.  
  134. // ---------------------------------------------------------------------------
  135. //        • ListenToMessage
  136. //
  137. //          Called by:    LBroadcaster::BroadcastMessage
  138. // ---------------------------------------------------------------------------
  139.  
  140. void
  141. CEvalDialog::ListenToMessage(
  142.     MessageT    inMessage, 
  143.     void        *ioParam )
  144. {
  145.     switch ( inMessage ) {
  146.  
  147.         case msg_CrossingsRule:            // msg from mCrossingsBox
  148.             AdjustFactoryButton();
  149.             break;
  150.         
  151.         case msg_FactorySettings:        // msg from mFactoryButton
  152.             SetDefaultValues( );
  153.             break;
  154.             
  155.         default:    
  156.             LGADialogBox::ListenToMessage( inMessage, ioParam );
  157.             break;
  158.     }
  159. }
  160.  
  161. // ---------------------------------------------------------------------------
  162. //        • AdjustFactoryButton    (PRIVATE)
  163. //
  164. //          Called by:    CEvalDialog::SetValues
  165. //                        CEvalDialog::ListenToMessage
  166. // ---------------------------------------------------------------------------
  167.  
  168. void
  169. CEvalDialog::AdjustFactoryButton( )
  170. {
  171.     if ( ! mFactoryButton -> IsEnabled() ) 
  172.          mFactoryButton -> Enable();
  173. }
  174.  
  175. // ---------------------------------------------------------------------------
  176. //        • FindCommandStatus
  177. //
  178. //          Called by:    LCommander::ProcessCommandStatus
  179. // ---------------------------------------------------------------------------
  180. //    Disable all menu items except for the one which opens the About box.
  181.  
  182. void
  183. CEvalDialog::FindCommandStatus(
  184.     CommandT    inCommand,
  185.     Boolean        &outEnabled,
  186.     Boolean&    /* outUsesMark */,
  187.     Char16&        /* outMark */,
  188.     Str255        /* outName */)
  189. {
  190.     outEnabled = false;
  191.     if (inCommand == cmd_About) {
  192.         outEnabled = true;
  193.     }
  194. }
  195.