// =========================================================================== // CSimlabToolbar.cp // ©1995 J. Rodden, DD/MF & Associates. All rights reserved // =========================================================================== #include "RuntimeTypes.h" #include "RuntimeMessages.h" #include "RuntimeResources.h" #include "CSimlabToolbar.h" #include "CSimlabListBox.h" #include #include <3DAttachments.h> #include <3DDrawingUtils.h> // --------------------------------------------------------------------------- // € CreateSimlabToolbarStream [static] // --------------------------------------------------------------------------- // This is the function you register with URegistrar to create a CSimlabToolbar // window from a resource CSimlabToolbar * CSimlabToolbar::CreateFromStream( LStream *inStream) { return (new CSimlabToolbar(inStream)); } // --------------------------------------------------------------------------- // € CSimlabToolbar // --------------------------------------------------------------------------- // The default constructor does nothing. CSimlabToolbar::CSimlabToolbar() { } // --------------------------------------------------------------------------- // € CSimlabToolbar // --------------------------------------------------------------------------- // The construct-from-stream constructor just constructs the base class. CSimlabToolbar::CSimlabToolbar(LStream *inStream) : UHiddenWindow(inStream) { } // --------------------------------------------------------------------------- // € FinishCreateSelf // --------------------------------------------------------------------------- // This member function gets called once the containment hierarchy that contains // this pane has been built. It gives us a chance to make the palette the listener // for the toolbar buttons. void CSimlabToolbar::FinishCreateSelf() { UReanimator::LinkListenerToControls(this, this, RidL_ToolbarButtons); AddAttachment(new C3DRaisedBorderAttachment()); } // --------------------------------------------------------------------------- // € ListenToMessage // --------------------------------------------------------------------------- // This is the function that handles clicks in the toolbar buttons. All we do // is send the message on to the current target. void CSimlabToolbar::ListenToMessage(MessageT inMessage, void *ioParam) { switch (inMessage) { case msg_AdjustState: AdjustState( *((ModelState*)ioParam) ); break; default: BroadcastMessage(inMessage, ioParam); break; } } // --------------------------------------------------------------------------- // € AdjustState // --------------------------------------------------------------------------- void CSimlabToolbar::AdjustState(ModelState inStatus) { Str255 theString; ResIDT theToolbarStringRsrc = 0; ResIDT theMenuStringRsrc = 0; if ( inStatus == NoModel || inStatus == NotExecutable ) { EnableCommandButtons(false); } switch (inStatus) { case NoModel: theToolbarStringRsrc = str_NoModel; break; case NotExecutable: theToolbarStringRsrc = str_NotExecutable; break; case Running: theToolbarStringRsrc = str_Running; break; case Paused: theToolbarStringRsrc = str_Paused; break; case Executable: EnableCommandButtons(true); case Stopped: theToolbarStringRsrc = str_Stopped; break; } LCaption *theCaption = (LCaption*) FindPaneByID(PaneID_StatusCptn); GetIndString( theString, STRx_Toolbar_Strs, theToolbarStringRsrc); theCaption->SetDescriptor((ConstStr255Param)theString); theCaption->Refresh(); } // --------------------------------------------------------------------------- // € EnableCommandButtons // --------------------------------------------------------------------------- void CSimlabToolbar::EnableCommandButtons(Boolean inTurnOn) { EnableButton(PaneID_RunBtn,inTurnOn); EnableButton(PaneID_PauseBtn,inTurnOn); EnableButton(PaneID_StopBtn,inTurnOn); EnableButton(PaneID_StepBtn,inTurnOn); EnableButton(PaneID_ResetBtn,inTurnOn); EnableButton(PaneID_GraphsBtn,inTurnOn); } // --------------------------------------------------------------------------- // € EnableButton // --------------------------------------------------------------------------- void CSimlabToolbar::EnableButton(PaneIDT inPaneID, Boolean inTurnOn) { LButton* theButton; theButton = (LButton*) FindPaneByID(inPaneID); if ( inTurnOn ) theButton->Enable(); else theButton->Disable(); theButton->Refresh(); } // --------------------------------------------------------------------------- // € DrawSelf // --------------------------------------------------------------------------- // This function gives the palette a light gray background. Since the "Erase // on Update" bit in the palette's PPob resource is set, we just set the // background color to gray and let the base class's DrawSelf() take care // of everything else, then we add an "embossed" look. void CSimlabToolbar::DrawSelf() { //LWindow::DrawSelf(); <-- not necessary, causes extra flashing of controls. RGBColor theColor; U3DDrawingUtils::Get3DBackColor(&theColor); ::RGBBackColor(&theColor); // set background color for text captions Rect theRect; CalcPortFrameRect(theRect); U3DDrawingUtils::Draw3DInsetHLine( 3, 0, theRect.right); U3DDrawingUtils::Draw3DInsetHLine( 30, 0, theRect.right); }