home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-16 | 5.6 KB | 217 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CGeneralDialog.cp ©1995-97 Timo Eloranta All rights reserved.
- // ===========================================================================
-
- #include "CGeneralDialog.h"
- #include "GraphGA_PaneIDs.h"
-
- #include <LString.h>
- #include <PP_Messages.h>
-
- #include <LCaption.h>
- #include <LGAEditField.h>
- #include <LGAPushButton.h>
-
- #include "CAGASlider.h"
-
- // ---------------------------------------------------------------------------
- // • CGeneralDialog
- //
- // Called by: URegistrar::CreateObject
- // ---------------------------------------------------------------------------
-
- CGeneralDialog::CGeneralDialog( LStream *inStream )
- : LGADialogBox( inStream )
- {
- }
-
- // ---------------------------------------------------------------------------
- // • InitDialog
- //
- // Called by: CGraphGAApp::ObeyCommand
- // ---------------------------------------------------------------------------
-
- void
- CGeneralDialog::InitDialog()
- {
- mPopCapt = (LCaption *) this -> FindPaneByID( capt_Pop );
- mGridCapt = (LCaption *) this -> FindPaneByID( capt_Grid );
-
- mFactoryButton = (LGAPushButton *) this -> FindPaneByID( but_FactorySettings );
-
- mTicksEdit = (LGAEditField *) this -> FindPaneByID( edit_Ticks );
-
- mPopSlider = (CAGASlider *) this -> FindPaneByID( slid_Pop );
- mGridSlider = (CAGASlider *) this -> FindPaneByID( slid_Grid );
-
- mTicksEdit -> Enable();
- mTicksEdit -> Activate();
- mTicksEdit -> SelectAll();
-
- if ( mFactoryButton)
- mFactoryButton -> AddListener( this );
-
- if ( mPopSlider )
- mPopSlider -> AddListener( this );
-
- if ( mGridSlider )
- mGridSlider -> AddListener( this );
- }
-
- // ---------------------------------------------------------------------------
- // • SetValues
- //
- // Called by: CGraphGAApp::ObeyCommand
- // ---------------------------------------------------------------------------
-
- void
- CGeneralDialog::SetValues( SGeneral &inGeneral )
- {
- if ( mTicksEdit )
- mTicksEdit -> SetValue( inGeneral.spendTime );
-
- if ( mPopCapt )
- mPopCapt -> SetValue( inGeneral.sizePop );
- if ( mPopSlider )
- mPopSlider -> SetValue( inGeneral.sizePop );
-
- if ( mGridCapt )
- SetGridValue( inGeneral.sizeGrid );
- if ( mGridSlider )
- mGridSlider -> SetValue( inGeneral.sizeGrid );
-
- }
-
- // ---------------------------------------------------------------------------
- // • SetGridValue (PRIVATE)
- //
- // Called by: CGeneralDialog::SetValues
- // CGeneralDialog::ListenToMessage
- // ---------------------------------------------------------------------------
-
- void
- CGeneralDialog::SetGridValue( Int16 inValue )
- {
- LStr255 theNbrString( (Int32) inValue );
- LStr255 theString( theNbrString );
-
- theString.Append( "\p x " );
- theString.Append( theNbrString );
-
- mGridCapt -> SetDescriptor( theString );
- }
-
- // ---------------------------------------------------------------------------
- // • GetValues
- //
- // Called by: CGraphGAApp::SetGeneralFromDialog
- // ---------------------------------------------------------------------------
-
- void
- CGeneralDialog::GetValues( SGeneral &outGeneral )
- {
- if ( mPopCapt )
- outGeneral.sizePop = mPopCapt -> GetValue();
- if ( mGridSlider )
- outGeneral.sizeGrid = mGridSlider -> GetValue();
- if ( mTicksEdit )
- outGeneral.spendTime = mTicksEdit -> GetValue();
- }
-
- // ---------------------------------------------------------------------------
- // • ListenToMessage
- //
- // Called by: LBroadcaster::BroadcastMessage
- // ---------------------------------------------------------------------------
-
- void
- CGeneralDialog::ListenToMessage(
- MessageT inMessage,
- void *ioParam )
- {
- switch ( inMessage ) {
-
- case slid_Pop:
- if ( mPopCapt ) {
- mPopCapt -> SetValue( *(Int32 *) ioParam );
- mPopCapt -> Draw( nil );
- AdjustFactoryButton();
- }
- break;
-
- case slid_Grid:
- if ( mGridCapt ) {
- SetGridValue( *(Int32 *) ioParam );
- mGridCapt -> Draw( nil );
- AdjustFactoryButton();
- }
- break;
-
- case msg_FactorySettings:
- SetDefaultValues();
- break;
-
- default:
- LGADialogBox::ListenToMessage( inMessage, ioParam );
- break;
- }
- }
-
- // ---------------------------------------------------------------------------
- // • SetDefaultValues (PRIVATE)
- //
- // Called by: CGeneralDialog::ListenToMessage
- // ---------------------------------------------------------------------------
-
- void
- CGeneralDialog::SetDefaultValues( )
- {
- if ( mTicksEdit )
- mTicksEdit -> SetValue( DEFAULT_SPEND_TIME );
-
- if ( mPopSlider )
- mPopSlider -> SetValue( DEFAULT_POP_SIZE );
-
- if ( mGridSlider )
- mGridSlider -> SetValue( DEFAULT_GRID_SIZE );
- }
-
- // ---------------------------------------------------------------------------
- // • AdjustFactoryButton
- //
- // Called by: CGeneralDialog::ListenToMessage
- // ---------------------------------------------------------------------------
-
- void
- CGeneralDialog::AdjustFactoryButton( )
- {
- if ( (mPopCapt -> GetValue()) == DEFAULT_POP_SIZE &&
- (mGridSlider -> GetValue()) == DEFAULT_GRID_SIZE &&
- (mTicksEdit -> GetValue()) == DEFAULT_SPEND_TIME )
- 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
- CGeneralDialog::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean& /* outUsesMark */,
- Char16& /* outMark */,
- Str255 /* outName */)
- {
- outEnabled = false;
- if (inCommand == cmd_About) {
- outEnabled = true;
- }
- }
-