home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DU Projects / Calc / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-22  |  4.5 KB  |  160 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 2 $
  2. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef FRAME_H
  6. #include "Frame.h"
  7. #endif
  8.  
  9. #ifndef PART_H
  10. #include "Part.h"
  11. #endif
  12.  
  13. #ifndef DEFINES_K
  14. #include "Defines.k"            // #defines
  15. #endif
  16.  
  17. // ----- Framework Layer -----
  18. #ifndef FWCONTXT_H
  19. #include "FWContxt.h"            // FW_CViewContext
  20. #endif
  21.  
  22. #ifndef FWTABBER_H
  23. #include "FWTabber.h"            // FW_CViewTabber
  24. #endif
  25.  
  26. #ifndef FWIDLE_H
  27. #include "FWIdle.h"                // FW_CIdler
  28. #endif
  29.  
  30. #ifndef FWBUTTON_H
  31. #include "FWButton.h"
  32. #endif
  33.  
  34. #ifndef FWEDVIEW_H
  35. #include "FWEdView.h"            // FW_CEditView
  36. #endif
  37.  
  38. #ifndef FWSTATIC_H
  39. #include "FWStatic.h"            // FW_CStaticText
  40. #endif
  41.  
  42. // ----- OS Layer -----
  43. #ifndef FWCFMRES_H
  44. #include "FWCFMRes.h"            // FW_PSharedLibraryResourceFile
  45. #endif
  46.  
  47.  
  48. #ifndef SLMIXOS_H
  49. #include "SLMixOS.h"            // FW_Beep
  50. #endif
  51.  
  52. // ----- Graphic Includes -----
  53. #ifndef FWRECT_H
  54. #include <FWRect.h>                // FW_CRect
  55. #endif
  56.  
  57. #ifndef FWPICSHP_H
  58. #include "FWPicShp.h"            // FW_CPictureShape
  59. #endif
  60.  
  61. //========================================================================================
  62. #ifdef FW_BUILD_MAC
  63. #pragma segment Calc
  64. #endif
  65.  
  66. //========================================================================================
  67. FW_DEFINE_AUTO(CCalcFrame)
  68.  
  69. //========================================================================================
  70. CCalcFrame::CCalcFrame(Environment* ev, ODFrame* odFrame, 
  71.                         FW_CPresentation* presentation, CCalcPart* calcPart)
  72.   : FW_CFrame(ev, odFrame, presentation, calcPart),
  73.       fCalcPart(calcPart),
  74.       fIdler(NULL),
  75.       fViewTabber(NULL)
  76. {
  77.     fIdler = FW_NEW(FW_CIdler, (this, 15));    // to blink text insertion point
  78.     fIdler->RegisterIdle(ev);                
  79.     FW_END_CONSTRUCTOR
  80. }
  81.  
  82. //----------------------------------------------------------------------------------------
  83. CCalcFrame::~CCalcFrame()
  84. {
  85.     FW_START_DESTRUCTOR
  86.     delete fIdler;
  87.     // fViewTabber deleted for us
  88. }
  89.  
  90. //----------------------------------------------------------------------------------------
  91. void 
  92. CCalcFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  93. {
  94.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  95.     // draw background picture from part editor shared library
  96.     FW_PSharedLibraryResourceFile resFile(ev);
  97.     const short kODFPictID = 2000;
  98.     const short kCalcPictID = 2001;
  99.     const FW_Fixed kWidth = FW_IntToFixed(280);
  100.     const FW_Fixed kHeight = FW_IntToFixed(200);
  101.      FW_CPictureShape::RenderPicture(context,
  102.                                     FW_CPicture(resFile, kCalcPictID),
  103.                                     FW_CRect(FW_IntToFixed(0), FW_IntToFixed(0), 
  104.                                                 kWidth, kHeight));
  105.  
  106. }
  107.  
  108. //----------------------------------------------------------------------------------------
  109. void 
  110. CCalcFrame::CreateSubViews(Environment* ev)
  111. {        
  112.     // WARNING: Make sure that classes created from resources won't be dead-stripped
  113.     //             Use the macro FW_DO_NOT_DEAD_STRIP for those classes which are not 
  114.     //             referenced anywhere else in your part's code.
  115.     FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
  116.     FW_DO_NOT_DEAD_STRIP(FW_CEditView);
  117.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  118.     
  119.     this->CreateSubViewsFromResource(ev, kCalcView);
  120.     FW_CButton* calcButton = (FW_CButton*)FindViewByID(ev, kCalculateButtonID);
  121.     calcButton->LinkControlTo(ev, this);
  122.     fViewTabber = new FW_CViewTabber(ev, this); 
  123. }
  124.  
  125.  
  126. //----------------------------------------------------------------------------------------
  127. void 
  128. CCalcFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
  129. {
  130.     if (notification.GetMessage() == FW_kButtonPressedMsg)  {
  131.         fCalcPart->MySetLoanAmount( MyGetEditValue(ev, kAmountEditID) );
  132.         fCalcPart->MySetAnnualInterestPercent( MyGetEditValue(ev, kInterestEditID) );
  133.         fCalcPart->MySetLoanYears( MyGetEditValue(ev, kYearsEditID) );
  134.  
  135.         double payment = fCalcPart->MyComputePayment(ev);
  136.         MySetEditValue(ev, kAnswerEditID, payment);
  137.     }
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. double 
  142. CCalcFrame::MyGetEditValue(Environment* ev, ODID viewID)
  143. {
  144.     FW_CEditView* view = (FW_CEditView*)FindViewByID(ev, viewID);
  145.     FW_CString valueStr = view->GetText(ev);
  146.     double value = valueStr.ParseAsRealNumber();
  147.     return (double)value;
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. void 
  152. CCalcFrame::MySetEditValue(Environment* ev, ODID viewID, double value, short fracDigits)
  153. {
  154.     FW_CString32 valueStr;
  155.     valueStr.ReplaceAllAsRealNumber(value, fracDigits);
  156.     FW_CEditView* view = (FW_CEditView*)FindViewByID(ev, viewID);
  157.     view->SetText(ev, valueStr);
  158. //    view->Invalidate(ev);
  159. }
  160.