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 / ODFDev / Draw / Sources / PatFrame.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  4.2 KB  |  151 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PatFrame.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef PATFRAME_H
  15. #include "PatFrame.h"
  16. #endif
  17.  
  18. #ifndef DRAWPART_H
  19. #include "DrawPart.h"
  20. #endif
  21.  
  22. // ----- Part Layer -----
  23.  
  24. #ifndef FWUTIL_H
  25. #include "FWUtil.h"
  26. #endif
  27.  
  28. #ifndef FWCONTXT_H
  29. #include "FWContxt.h"
  30. #endif
  31.  
  32. // ----- OS Layer -----
  33.  
  34. #ifndef FWWINDOW_H
  35. #include "FWWindow.h"
  36. #endif
  37.  
  38. #ifndef FWMEMMGR_H
  39. #include "FWMemMgr.h"
  40. #endif
  41.  
  42. #ifndef FWEVENT_H
  43. #include "FWEvent.h"
  44. #endif
  45.  
  46. #ifndef FWCOLOR_H
  47. #include "FWColor.h"
  48. #endif
  49.  
  50. #ifndef FWRECSHP_H
  51. #include "FWRecShp.h"
  52. #endif
  53.  
  54. //========================================================================================
  55. // Runtime Informations
  56. //========================================================================================
  57.  
  58. #ifdef FW_BUILD_MAC
  59. #pragma segment odfdrawframes
  60. #endif
  61.  
  62. FW_DEFINE_AUTO(CPatternFrame)
  63.     
  64. //========================================================================================
  65. // CLASS CPatternFrame
  66. //========================================================================================
  67.  
  68. //----------------------------------------------------------------------------------------
  69. // CPatternFrame::CPatternFrame
  70. //----------------------------------------------------------------------------------------
  71.  
  72. CPatternFrame::CPatternFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CDrawPart *drawPart) :
  73.     CFloatingWindowFrame(ev, odFrame, presentation, drawPart),
  74.     fGrid(2, 6, FW_CPoint(FW_IntToFixed(2), FW_IntToFixed(2)), FW_CPoint(kPatternCellSize, kPatternCellSize), FW_kFixedPos1)
  75. {
  76. }
  77.  
  78. //----------------------------------------------------------------------------------------
  79. // CPatternFrame::~CPatternFrame
  80. //----------------------------------------------------------------------------------------
  81.  
  82. CPatternFrame::~CPatternFrame()
  83. {
  84. }
  85.  
  86. //----------------------------------------------------------------------------------------
  87. //    CPatternFrame::Draw
  88. //----------------------------------------------------------------------------------------
  89.  
  90. void CPatternFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  91. {
  92.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  93.     vc.SetMapping(fMapping);
  94.  
  95.     EraseBackground(ev, vc);
  96.  
  97.     //    ----- Draw the grid -----
  98.     fGrid.DrawGridBorders(vc);
  99.     
  100.     // ----- Draw each color -----
  101.     FW_CRect rect;
  102.     FW_CRectShape rectShape(FW_kZeroRect, FW_kFill);
  103.     for (unsigned long index = 0; index < 12; index++)
  104.     {
  105.         fGrid.GetCellInterior(index, rect);
  106.         rectShape.SetRectangle(rect);
  107.         rectShape.GetStyle().SetPattern(fDrawPart->GetPattern(index));
  108.         rectShape.Render(vc);
  109.     }
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. //    CPatternFrame::DoMouseDown
  114. //----------------------------------------------------------------------------------------
  115.  
  116. FW_Boolean CPatternFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  117. {
  118.     FW_CPoint where = theMouseEvent.GetLogicalMousePosition(ev, fMapping);
  119.     
  120.     unsigned long patIndex;    
  121.     if (fGrid.FindCell(where, patIndex))
  122.     {
  123.         if (theMouseEvent.IsCopyModifier(ev))
  124.             fDrawPart->SetFramePattern(ev, patIndex);
  125.         else
  126.             fDrawPart->SetFillPattern(ev, patIndex);    
  127.     }
  128.  
  129.     return TRUE;
  130. }
  131.  
  132. //----------------------------------------------------------------------------------------
  133. // CPatternFrame::FacetAdded
  134. //----------------------------------------------------------------------------------------
  135. //    When ODWindow moves back to ODFrame we will be able to move this code
  136. //    back to the constructor
  137.  
  138. void CPatternFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  139. {
  140.     // ----- Call inherited first -----
  141.     CFloatingWindowFrame::FacetAdded(ev, facet, facetCount);
  142.     
  143.     // ----- Resize my Window -----
  144.     FW_CRect gridRect;
  145.     fGrid.GetExteriorGridRect(gridRect);
  146.     gridRect.Inset(-FW_IntToFixed(2), -FW_IntToFixed(2));
  147.     FW_CPoint windowSize(gridRect.Width(), gridRect.Height());
  148.     GetWindow(ev)->SetWindowSize(ev, windowSize);
  149. }
  150.  
  151.