home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DUProjects / Calc / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  3.8 KB  |  154 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 1 $
  2. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //================================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef FRAME_H
  10. #include "Frame.h"
  11. #endif
  12.  
  13. #ifndef DEFINES_K
  14. #include "Defines.k"
  15. #endif
  16.  
  17. #ifndef BINDING_K
  18. #include "Binding.k"
  19. #endif
  20.  
  21. // ----- Framework Includes -----
  22. #ifndef FWUTIL_H
  23. #include "FWUtil.h"
  24. #endif
  25.  
  26. #ifndef FWABOUT_H
  27. #include "FWAbout.h"        //::FW_About()
  28. #endif
  29.  
  30. #include "SLMixOS.h"        // FW_GetMainScreenBounds
  31.  
  32. //--- SOM library ------------------------------------------------
  33. #ifndef SOM_DevUniv_SFinance_xih
  34. #include "SFinance.xih"                // DevUniv_SFinance SOM library
  35. #endif
  36.  
  37. //==============================================================================
  38. #ifdef FW_BUILD_MAC
  39. #pragma segment Calc
  40. #endif
  41.  
  42. FW_DEFINE_AUTO(CCalcPart)
  43.  
  44. //==============================================================================
  45. CCalcPart::CCalcPart(ODPart* odPart)
  46.   :    FW_CPart(odPart, FW_gInstance, kPartInfoID),
  47.      fPresentation(NULL),
  48.       fLoanAmount(0),
  49.       fAnnualInterestPercent(0),
  50.       fLoanYears(0),
  51.       fMonthlyPayment(0),
  52.       fSOMFinanceCalc(NULL)
  53. {
  54. }
  55.  
  56. //--------------------------------------------------------------------------------
  57. CCalcPart::~CCalcPart()
  58. {
  59.     delete fSOMFinanceCalc;
  60. }
  61.  
  62. //--------------------------------------------------------------------------------
  63. void 
  64. CCalcPart::Initialize(Environment* ev)    // Override
  65. {
  66.     FW_CPart::Initialize(ev);
  67.     FW_CSelection* selection = NULL;
  68.     const ODType kMainPresentation = "Apple:Presentation:Calc";
  69.     fPresentation = this->RegisterPresentation(ev, kMainPresentation, true, selection);
  70.     fSOMFinanceCalc = new DevUniv_SFinance;
  71. }
  72.  
  73. //--------------------------------------------------------------------------------
  74. FW_CFrame* 
  75. CCalcPart::NewFrame(Environment* ev, ODFrame* odFrame,
  76.                         FW_CPresentation* presentation, FW_Boolean fromStorage)    // Override
  77. {
  78.     FW_UNUSED(presentation);
  79.     FW_UNUSED(fromStorage);
  80.     return FW_NEW(CCalcFrame, (ev, odFrame, presentation, this));
  81. }
  82.  
  83. //--------------------------------------------------------------------------------
  84. FW_CContent* 
  85. CCalcPart::NewPartContent(Environment* ev)
  86. {
  87.     return NULL;
  88. }
  89.  
  90. //--------------------------------------------------------------------------------
  91. FW_Boolean 
  92. CCalcPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  93. {
  94.     FW_Boolean menuHandled = true;
  95.     switch (theMenuEvent.GetCommandID(ev))
  96.     {
  97.         case kODCommandAbout:
  98.             ::FW_About(ev, this, kAbout);
  99.             break;
  100.  
  101.         default:
  102.             menuHandled = false;
  103.     }
  104.     return menuHandled;
  105. }
  106.  
  107. //-------------------------------------------------------------------
  108. CalcFloat 
  109. CCalcPart::MyComputePayment(Environment* ev)
  110. {
  111.     fMonthlyPayment = fSOMFinanceCalc->Payment(ev, fLoanAmount, 
  112.                                                 fAnnualInterestPercent,
  113.                                                 fLoanYears);
  114.     return fMonthlyPayment;
  115. }
  116.  
  117. //-------------------------------------------------------------------
  118. void 
  119. CCalcPart::MySetLoanAmount(CalcFloat borrowed)
  120. {
  121.     fLoanAmount = borrowed;
  122. }
  123.  
  124. //-------------------------------------------------------------------
  125. void 
  126. CCalcPart::MySetAnnualInterestPercent(CalcFloat interest)
  127. {
  128.     fAnnualInterestPercent = interest;
  129. }
  130.  
  131. //-------------------------------------------------------------------
  132. void 
  133. CCalcPart::MySetLoanYears(CalcFloat years)
  134. {
  135.     fLoanYears = years;
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. FW_CWindow* 
  140. CCalcPart::NewDocumentWindow(Environment* ev)
  141. {    
  142.     FW_CRect screenBounds;
  143.     ::FW_GetMainScreenBounds(screenBounds);
  144.     screenBounds.Inset(FW_IntToFixed(3), FW_IntToFixed(3));
  145.     
  146.     return new FW_CWindow(ev,
  147.                         this,
  148.                          FW_CPart::gViewAsFrameToken,
  149.                         fPresentation,
  150.                         FW_CPoint(FW_IntToFixed(280), FW_IntToFixed(200)),
  151.                         screenBounds.TopLeft(),
  152.                         FW_kDocumentWindow);
  153. }
  154.