home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 4.4 KB | 150 lines | [TEXT/CWIE] |
- // Release Version: $ ODF 1 $
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- //=======================================================================
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k" // #defines
- #endif
-
- // ----- Framework Layer -----
- #ifndef FWUTIL_H
- #include "FWUtil.h" // FW_CFacetContext, FW_Beep()
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h" // FW_CViewContext
- #endif
-
- #include "FWTabber.h" // FW_CViewTabber
- #include "FWIdle.h" // FW_CIdler
-
- #ifndef FWBUTTON_H
- #include "FWButton.h"
- #endif
-
- #ifndef FWEDVIEW_H
- #include "FWEdView.h"
- #endif
-
- // OS Layer -------------------------
- #ifndef SLMIXCOS_H
- #include "SLMixOS.h" // FW_Beep
- #endif
-
- // ----- Graphic Includes -----
- #ifndef FWRECT_H
- #include <FWRect.h> // FW_CRect
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h" // FW_CRectShape
- #endif
-
- //========================================================================================
- #ifdef FW_BUILD_MAC
- #pragma segment Calc
- #endif
-
- //========================================================================================
- FW_DEFINE_AUTO(CCalcFrame)
-
- //========================================================================================
- CCalcFrame::CCalcFrame(Environment* ev, ODFrame* odFrame,
- FW_CPresentation* presentation, CCalcPart* calcPart)
- : FW_CFrame(ev, odFrame, presentation, calcPart),
- fCalcPart(calcPart),
- fIdler(NULL),
- fViewTabber(NULL)
- {
- fIdler = FW_NEW(FW_CIdler, (this, 15)); // to blink text insertion point
- fIdler->RegisterIdle(ev);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- CCalcFrame::~CCalcFrame()
- {
- FW_START_DESTRUCTOR
- delete fIdler;
- // fViewTabber deleted for us
- }
-
- //----------------------------------------------------------------------------------------
- void
- CCalcFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape) // Override
- {
- FW_CViewContext context(ev, this, odFacet, invalidShape);
- // draw background picture from part editor shared library
- FW_CSharedLibraryResourceFile resFile(ev);
- const short kODFPictID = 2000;
- const short kCalcPictID = 2001;
- const FW_Fixed kWidth = FW_IntToFixed(280);
- const FW_Fixed kHeight = FW_IntToFixed(200);
- FW_CPictureShape::RenderPicture(context,
- FW_CPicture(resFile, kCalcPictID),
- FW_CRect(FW_IntToFixed(0), FW_IntToFixed(0),
- kWidth, kHeight));
-
- }
-
- //----------------------------------------------------------------------------------------
- void
- CCalcFrame::CreateSubViews(Environment* ev)
- {
- // WARNING: Make sure that classes created from resources won't be dead-stripped
- // Use the macro FW_DO_NOT_DEAD_STRIP for those classes which are not
- // referenced anywhere else in your part's code.
- FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
- FW_DO_NOT_DEAD_STRIP(FW_CEditView);
- FW_DO_NOT_DEAD_STRIP(FW_CButton);
-
- this->CreateSubViewsFromResource(ev, kCalcView);
- FW_CButton* calcButton = (FW_CButton*)FindViewById(ev, kCalculateButtonID);
- calcButton->LinkControlTo(ev, this);
- fViewTabber = new FW_CViewTabber(ev, this);
- }
-
-
- //----------------------------------------------------------------------------------------
- void
- CCalcFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
- {
- if (notification.GetMessage() == FW_kButtonPressedMsg) {
- fCalcPart->MySetLoanAmount( MyGetEditValue(ev, kAmountEditID) );
- fCalcPart->MySetAnnualInterestPercent( MyGetEditValue(ev, kInterestEditID) );
- fCalcPart->MySetLoanYears( MyGetEditValue(ev, kYearsEditID) );
-
- double payment = fCalcPart->MyComputePayment(ev);
- MySetEditValue(ev, kAnswerEditID, payment);
- }
- }
-
- //----------------------------------------------------------------------------------------
- double
- CCalcFrame::MyGetEditValue(Environment* ev, ODID viewID)
- {
- FW_CEditView* view = (FW_CEditView*)FindViewById(ev, viewID);
- FW_CString valueStr = view->GetText(ev);
- double value = valueStr.ParseAsRealNumber();
- return (double)value;
- }
-
- //----------------------------------------------------------------------------------------
- void
- CCalcFrame::MySetEditValue(Environment* ev, ODID viewID, double value, short fracDigits)
- {
- FW_CString32 valueStr;
- valueStr.ReplaceAllAsRealNumber(value, fracDigits);
- FW_CEditView* view = (FW_CEditView*)FindViewById(ev, viewID);
- view->SetText(ev, valueStr);
- // view->Invalidate(ev);
- }
-