home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / Developer University / DUProjects / Windoid / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-03-29  |  4.8 KB  |  176 lines  |  [TEXT/CWIE]

  1. //    Copyright © 1995 Apple Computer, Inc. All rights reserved.
  2. //    Release Version:    $ 1.0 d8 $
  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 BINDING_K
  14. #include "Binding.k"
  15. #endif
  16.  
  17. #ifndef FRAME_H
  18. #include "Frame.h"
  19. #endif
  20.  
  21. // ----- Framework Layer -----
  22. #ifndef FWUTIL_H
  23. #include "FWUtil.h"                // FW_CFacetContext, FW_Beep()
  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. // ----- Graphic Includes -----
  36. #ifndef FWRECT_H
  37. #include <FWRect.h>                // FW_CRect
  38. #endif
  39.  
  40. #ifndef FWRECSHP_H
  41. #include "FWRecShp.h"            // FW_CRectShape
  42. #endif
  43.  
  44. #ifndef FWPICSHP_H
  45. #include "FWPicShp.h"            // FW_PPicture, FW_CPictureShape
  46. #endif
  47.  
  48. #ifndef FWCONTXT_H
  49. #include "FWContxt.h"            // FW_CViewContext
  50. #endif
  51.  
  52. //=============================================================================
  53. #ifdef FW_BUILD_MAC
  54. #pragma segment Windoid
  55. #endif
  56.  
  57. FW_DEFINE_AUTO(CMainFrame)
  58. //=============================================================================
  59. CMainFrame::CMainFrame(Environment* ev, ODFrame* odFrame, 
  60.                             FW_CPresentation* presentation, CWindoidPart* part)
  61.   : FW_CFrame(ev, odFrame, presentation, part)
  62. {
  63.     FW_Boolean showPalette = this->IsRoot(ev);
  64.     part->MyMakePalette(ev, showPalette);
  65.     FW_END_CONSTRUCTOR
  66. }
  67.  
  68. //------------------------------------------------------------------------------
  69. CMainFrame::~CMainFrame()
  70. {
  71.     FW_START_DESTRUCTOR
  72. }
  73.  
  74. //------------------------------------------------------------------------------
  75. void 
  76. CMainFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  77. {
  78.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  79.     FW_CRect box = this->GetBounds(ev);    
  80.     FW_CRectShape::RenderRect(context, box, FW_kFill, FW_kRGBGreen);
  81. }
  82.  
  83. //=============================================================================
  84. const short kNumberOfColumns     = 6;
  85. const short kNumberOfRows         = 1;
  86. const FW_Fixed kCellSizeV     = FW_IntToFixed(42);
  87. const FW_Fixed kCellSizeH     = FW_IntToFixed(41);
  88.  
  89. FW_DEFINE_AUTO(CPaletteFrame)
  90.  
  91. //------------------------------------------------------------------------------
  92. CPaletteFrame::CPaletteFrame(Environment* ev, ODFrame* odFrame, 
  93.                             FW_CPresentation* presentation, CWindoidPart* part)
  94.   : FW_CFrame(ev, odFrame, presentation, part),
  95.     fWindoidPart(part),
  96.     fSelectedRow(0),
  97.     fSelectedCol(0)
  98. {
  99.     this->SetCanBeActiveFrame(ev, false);
  100.     FW_END_CONSTRUCTOR
  101. }
  102.  
  103. //------------------------------------------------------------------------------
  104. CPaletteFrame::~CPaletteFrame()
  105. {
  106.     FW_START_DESTRUCTOR
  107. }
  108.  
  109. //------------------------------------------------------------------------------
  110. void 
  111. CPaletteFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  112. {
  113.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  114.     FW_CRect box = this->GetBounds(ev);    
  115.  
  116.     // Draw Picture that looks like a list of Icons
  117.     FW_CSharedLibraryResourceFile resFile(ev);
  118.     FW_CPicture pict(resFile, kPalettePictID);
  119.     FW_CPictureShape shape(pict, box);
  120.     shape.Render(context);
  121.     
  122.     // Indicate "selected" Icon
  123.     FW_CRect rect;
  124.     this->GetCellRectangle(fSelectedRow, fSelectedCol, rect);
  125.     FW_CRectShape rectShape(rect, FW_kFrame);
  126.     rectShape.Render(context);
  127. }
  128.  
  129. //------------------------------------------------------------------------------
  130. FW_Boolean 
  131. CPaletteFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  132. {    
  133.     // Get the mouse in local coordinates
  134.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  135.     
  136.     // See what cell was hit and store in frame
  137.     if (this->FindCell(where, fSelectedRow, fSelectedCol)) {
  138.         FW_CRect frameRect = this->GetBounds(ev);    
  139.         this->Invalidate(ev, frameRect);    
  140.     }
  141.     return TRUE;                // we handled event
  142. }
  143.  
  144. //------------------------------------------------------------------------------
  145. FW_Boolean 
  146. CPaletteFrame::FindCell(const FW_CPoint& where, unsigned short& row, 
  147.                                                     unsigned short& column) const
  148. {
  149.     // Iterate over rows and columns and see if a cell was hit
  150.     FW_CRect rect;
  151.     for (unsigned short x = 0; x < kNumberOfColumns; x++)
  152.         for (unsigned short y = 0; y < kNumberOfRows; y++)
  153.         {
  154.             // calculate geometry of this grid cell
  155.             this->GetCellRectangle(y, x, rect);
  156.             if (rect.Contains(where))
  157.             {
  158.                 // got one
  159.                 column = x;
  160.                 row = y;
  161.                 return TRUE;
  162.             }
  163.         }
  164.     
  165.     return FALSE;
  166. }
  167. //------------------------------------------------------------------------------
  168. void 
  169. CPaletteFrame::GetCellRectangle(unsigned short row, unsigned short column, 
  170.                                                         FW_CRect& rect) const
  171. {
  172.     // Get geometry of a cell in a grid
  173.     rect.Set(FW_IntToFixed(0),FW_IntToFixed(0), kCellSizeH, kCellSizeV);
  174.     rect.Place(kCellSizeH * FW_IntToFixed(column), kCellSizeV * FW_IntToFixed(row) );
  175. }
  176.