home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-16 | 8.0 KB | 269 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CTerminationDialog.cp ©1995-97 Timo Eloranta All rights reserved.
- // ===========================================================================
-
- #include "CTerminationDialog.h"
- #include "GraphGA_PaneIDs.h"
-
- #include <PP_Messages.h>
- #include <UReanimator.h>
-
- #include <LGAEditField.h>
- #include <LGAPushButton.h>
- #include <LGACheckbox.h>
-
-
- // ---------------------------------------------------------------------------
- // • CTerminationDialog
- //
- // Called by: URegistrar::CreateObject
- // ---------------------------------------------------------------------------
-
- CTerminationDialog::CTerminationDialog( LStream *inStream )
- : LGADialogBox( inStream )
- {
- }
-
- // ---------------------------------------------------------------------------
- // • InitDialog
- //
- // Called by: CGraphGAApp::ObeyCommand
- // ---------------------------------------------------------------------------
-
- void
- CTerminationDialog::InitDialog()
- {
- mFactoryButton = (LGAPushButton *) this -> FindPaneByID( but_FactorySettings );
-
- mMaxGenBox = (LGACheckbox *) this -> FindPaneByID( cbox_MaxGen );
- mMaxGenNoBox = (LGACheckbox *) this -> FindPaneByID( cbox_MaxGenNo );
- mMaxTimeBox = (LGACheckbox *) this -> FindPaneByID( cbox_MaxTime );
- mMaxTimeNoBox = (LGACheckbox *) this -> FindPaneByID( cbox_MaxTimeNo );
- mCrossingsBox = (LGACheckbox *) this -> FindPaneByID( cbox_NoCrossings );
-
- UReanimator::LinkListenerToControls( this, this, WIND_Terminate );
-
- mMaxGenEdit = (LGAEditField *) this -> FindPaneByID( edit_MaxGen );
- mMaxGenNoEdit = (LGAEditField *) this -> FindPaneByID( edit_MaxGenNo );
- mMaxTimeEdit = (LGAEditField *) this -> FindPaneByID( edit_MaxTime );
- mMaxTimeNoEdit = (LGAEditField *) this -> FindPaneByID( edit_MaxTimeNo );
- }
-
- // ---------------------------------------------------------------------------
- // • SetValues
- //
- // Called by: CGraphGAApp::ObeyCommand
- // ---------------------------------------------------------------------------
-
- void
- CTerminationDialog::SetValues( STermination &inTermination )
- {
- mMaxGenBox -> SetValue( inTermination.stopMaxGenTotal );
- mMaxGenNoBox -> SetValue( inTermination.stopMaxGenNoChange );
- mMaxTimeBox -> SetValue( inTermination.stopMaxTimeTotal );
- mMaxTimeNoBox -> SetValue( inTermination.stopMaxTimeNoChange );
- mCrossingsBox -> SetValue( inTermination.stopNoCrossings );
-
- mMaxGenEdit -> SetValue( inTermination.maxGenTotal );
- mMaxGenNoEdit -> SetValue( inTermination.maxGenNoChange );
- mMaxTimeEdit -> SetValue( inTermination.maxTimeTotal / 60L );
- mMaxTimeNoEdit -> SetValue( inTermination.maxTimeNoChange / 60L );
-
- if ( ! inTermination.stopMaxGenTotal ) {
- mMaxGenEdit -> Disable();
- mMaxGenEdit -> Deactivate();
- }
- if ( ! inTermination.stopMaxGenNoChange ) {
- mMaxGenNoEdit -> Disable();
- mMaxGenNoEdit -> Deactivate();
- }
- if ( ! inTermination.stopMaxTimeTotal ) {
- mMaxTimeEdit -> Disable();
- mMaxTimeEdit -> Deactivate();
- }
- if ( ! inTermination.stopMaxTimeNoChange ) {
- mMaxTimeNoEdit -> Disable();
- mMaxTimeNoEdit -> Deactivate();
- }
-
- if ( inTermination.stopMaxGenTotal ) {
- mMaxGenEdit -> SelectAll();
- SetLatentSub( mMaxGenEdit );
- }
- else if ( inTermination.stopMaxGenNoChange ) {
- mMaxGenNoEdit -> SelectAll();
- SetLatentSub( mMaxGenNoEdit );
- }
- else if ( inTermination.stopMaxTimeTotal ) {
- mMaxTimeEdit -> SelectAll();
- SetLatentSub( mMaxTimeEdit );
- }
- else if ( inTermination.stopMaxTimeNoChange ) {
- mMaxTimeNoEdit -> SelectAll();
- SetLatentSub( mMaxTimeNoEdit );
- }
-
- AdjustFactoryButton();
- }
-
- // ---------------------------------------------------------------------------
- // • SetDefaultValues (PRIVATE)
- //
- // Called by: CTerminationDialog::ListenToMessage
- // ---------------------------------------------------------------------------
-
- void
- CTerminationDialog::SetDefaultValues( )
- {
- mMaxGenEdit -> SetValue( DEFAULT_MAX_GEN_TOTAL );
- mMaxGenNoEdit -> SetValue( DEFAULT_MAX_GEN_NO_CHANGE );
- mMaxTimeEdit -> SetValue( DEFAULT_MAX_TIME_TOTAL / 60L );
- mMaxTimeNoEdit -> SetValue( DEFAULT_MAX_TIME_NO_CHANGE / 60L );
-
- mMaxGenBox -> SetValue( Button_Off );
- mMaxGenNoBox -> SetValue( Button_Off );
- mMaxTimeBox -> SetValue( Button_Off );
- mMaxTimeNoBox -> SetValue( Button_Off );
- mCrossingsBox -> SetValue( Button_Off );
- }
-
- // ---------------------------------------------------------------------------
- // • GetValues
- //
- // Called by: CGraphGAApp::SetTerFromDialog
- // ---------------------------------------------------------------------------
-
- void
- CTerminationDialog::GetValues( STermination &outTermination )
- {
- outTermination.stopMaxGenTotal = mMaxGenBox -> GetValue();
- outTermination.stopMaxGenNoChange = mMaxGenNoBox -> GetValue();
- outTermination.stopMaxTimeTotal = mMaxTimeBox -> GetValue();
- outTermination.stopMaxTimeNoChange = mMaxTimeNoBox -> GetValue();
- outTermination.stopNoCrossings = mCrossingsBox -> GetValue();
-
- outTermination.maxGenTotal = mMaxGenEdit -> GetValue();
- outTermination.maxGenNoChange = mMaxGenNoEdit -> GetValue();
- outTermination.maxTimeTotal = (mMaxTimeEdit -> GetValue()) * 60L;
- outTermination.maxTimeNoChange = (mMaxTimeNoEdit -> GetValue()) * 60L;
- }
-
- // ---------------------------------------------------------------------------
- // • ListenToMessage
- //
- // Called by: LBroadcaster::BroadcastMessage
- // ---------------------------------------------------------------------------
-
- void
- CTerminationDialog::ListenToMessage(
- MessageT inMessage,
- void *ioParam )
- {
- switch ( inMessage ) {
-
- case msg_MaxGen:
- if ( mMaxGenBox -> GetValue() ) {
- SwitchTarget( mMaxGenEdit );
- mMaxGenEdit -> Enable();
- mMaxGenEdit -> Activate();
- mMaxGenEdit -> SelectAll();
- } else {
- mMaxGenEdit -> Disable();
- mMaxGenEdit -> Deactivate();
- }
- AdjustFactoryButton();
- break;
-
- case msg_MaxGenNo:
- if ( mMaxGenNoBox -> GetValue() ) {
- SwitchTarget( mMaxGenNoEdit );
- mMaxGenNoEdit -> Enable();
- mMaxGenNoEdit -> Activate();
- mMaxGenNoEdit -> SelectAll();
- } else {
- mMaxGenNoEdit -> Disable();
- mMaxGenNoEdit -> Deactivate();
- }
- AdjustFactoryButton();
- break;
-
- case msg_MaxTime:
- if ( mMaxTimeBox -> GetValue() ) {
- SwitchTarget( mMaxTimeEdit );
- mMaxTimeEdit -> Enable();
- mMaxTimeEdit -> Activate();
- mMaxTimeEdit -> SelectAll();
- } else {
- mMaxTimeEdit -> Disable();
- mMaxTimeEdit -> Deactivate();
- }
- AdjustFactoryButton();
- break;
-
- case msg_MaxTimeNo:
- if ( mMaxTimeNoBox -> GetValue() ) {
- SwitchTarget( mMaxTimeNoEdit );
- mMaxTimeNoEdit -> Enable();
- mMaxTimeNoEdit -> Activate();
- mMaxTimeNoEdit -> SelectAll();
- } else {
- mMaxTimeNoEdit -> Disable();
- mMaxTimeNoEdit -> Deactivate();
- }
- AdjustFactoryButton();
- break;
-
- case msg_NoCrossings:
- AdjustFactoryButton();
- break;
-
- case msg_FactorySettings:
- SetDefaultValues( );
- break;
-
- default:
- LGADialogBox::ListenToMessage( inMessage, ioParam );
- break;
- }
- }
-
- // ---------------------------------------------------------------------------
- // • AdjustFactoryButton (PRIVATE)
- //
- // Called by: CTerminationDialog::SetValues
- // CTerminationDialog::ListenToMessage
- // ---------------------------------------------------------------------------
-
- void
- CTerminationDialog::AdjustFactoryButton( )
- {
- if ( ! ( mMaxGenBox -> GetValue() || mMaxGenNoBox -> GetValue() ||
- mMaxTimeBox -> GetValue() || mMaxTimeNoBox -> GetValue() ||
- mCrossingsBox -> GetValue() ) )
- mFactoryButton -> Disable();
- else
- if ( ! mFactoryButton -> IsEnabled() )
- mFactoryButton -> Enable();
- }
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- //
- // Called by: LCommander::ProcessCommandStatus
- // ---------------------------------------------------------------------------
- // Disable all menu items except for the one which opens the About box.
-
- void
- CTerminationDialog::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean& /* outUsesMark */,
- Char16& /* outMark */,
- Str255 /* outName */)
- {
- outEnabled = false;
- if (inCommand == cmd_About) {
- outEnabled = true;
- }
- }
-