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 / Mnu / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  2.9 KB  |  125 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 DEFINES_K
  10. #include "Defines.k"
  11. #endif
  12.  
  13. #ifndef FRAME_H
  14. #include "Frame.h"
  15. #endif
  16.  
  17. // ----- Framework Layer -----
  18. #ifndef FWUTIL_H
  19. #include "FWUtil.h"                // FW_CFacetContext, FW_Beep()
  20. #endif
  21.  
  22. #ifndef FWCONTXT_H
  23. #include "FWContxt.h"            // FW_CViewContext
  24. #endif
  25.  
  26. // ----- OS Layer -----
  27. #ifndef FWMENU_H
  28. #include "FWMenu.h"                // FW_CMenuBar, etc.
  29. #endif
  30.  
  31. #ifndef FWEVENT_H
  32. #include "FWEvent.h"            // FW_CMenuEvent, FW_CMouseEvent
  33. #endif
  34.  
  35. #ifndef FWALERT_H
  36. #include "FWAlert.h"            // FW_CAlert
  37. #endif
  38.  
  39. #ifndef SLMIXCOS_H
  40. #include "SLMixOS.h"            // FW_Beep
  41. #endif
  42.  
  43. // ----- Graphic Includes -----
  44. #ifndef FWRECT_H
  45. #include <FWRect.h>                // FW_CRect
  46. #endif
  47.  
  48. #ifndef FWRECSHP_H
  49. #include "FWRecShp.h"            // FW_CRectShape
  50. #endif
  51.  
  52. //========================================================================================
  53. #ifdef FW_BUILD_MAC
  54. #pragma segment Mnu
  55. #endif
  56.  
  57. FW_DEFINE_AUTO(CMnuFrame)
  58.  
  59. //========================================================================================
  60. CMnuFrame::CMnuFrame(Environment* ev, ODFrame* odFrame, 
  61.                                     FW_CPresentation* presentation, CMnuPart* mnuPart)
  62.   : FW_CFrame(ev, odFrame, presentation, mnuPart),
  63.     fMnuPart(mnuPart),
  64.     fSoundOn(true)
  65. {
  66. }
  67.  
  68. //----------------------------------------------------------------------------------------
  69. CMnuFrame::~CMnuFrame()
  70. {
  71. }
  72.  
  73. //----------------------------------------------------------------------------------------
  74. void 
  75. CMnuFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  76. {
  77.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  78.     FW_CRect invalidRect;
  79.     context.GetClipRect(invalidRect);
  80.  
  81.     FW_CRectShape::RenderRect(context, invalidRect, FW_kFill, FW_kWhiteEraseInk); // erase
  82.  
  83.     FW_CRect mnuRect = this->GetBounds(ev);
  84.     FW_CRectShape rectShape(mnuRect, FW_kFill);
  85.     rectShape.GetInk().SetForeColor(FW_kRGBLightGray);
  86.     rectShape.Render(context);
  87. }
  88.  
  89. //----------------------------------------------------------------------------------------
  90. FW_Boolean 
  91. CMnuFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus,
  92.                                                     FW_Boolean isRoot)    // Override
  93. {
  94.     if (hasMenuFocus) {
  95.         menuBar->EnableCommand(ev, cItemThreeCommand, true);
  96.         menuBar->EnableAndCheckCommand(ev, cSoundCommand, 
  97.                                                 true,             // enable
  98.                                                 fSoundOn);        // checkmark
  99.     }
  100.     return false;
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. FW_Boolean 
  105. CMnuFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  106. {
  107.     FW_Boolean menuHandled = true;
  108.     
  109.     switch (theMenuEvent.GetCommandID(ev))
  110.     {
  111.         case cItemThreeCommand:
  112.             if (fSoundOn) FW_Beep();
  113.             break;
  114.  
  115.         case cSoundCommand:
  116.             fSoundOn = !fSoundOn;
  117.             break;
  118.  
  119.         default:
  120.             menuHandled = false;
  121.     }
  122.     return menuHandled;
  123. }
  124.  
  125.