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 / ODFDev / Draw / Sources / OvalShp.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  6.7 KB  |  265 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                OvalShp.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 BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef OVALSHP_H
  23. #include "OvalShp.h"
  24. #endif
  25.  
  26. #ifndef UTILS_H
  27. #include "Utils.h"
  28. #endif
  29.  
  30. #ifndef CONSTANT_H
  31. #include "Constant.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWFRMING_H
  61. #include "FWFrming.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWSELECT_H
  69. #include "FWSelect.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWRECSHP_H
  83. #include "FWRecShp.h"
  84. #endif
  85.  
  86. #ifndef FWTXTBOX_H
  87. #include "FWTxtBox.h"
  88. #endif
  89.  
  90. #ifndef FWLINSHP_H
  91. #include "FWLinShp.h"
  92. #endif
  93.  
  94. #ifndef FWOVLSHP_H
  95. #include "FWOvlShp.h"
  96. #endif
  97.  
  98. #ifndef FWRRCSHP_H
  99. #include "FWRRcShp.h"
  100. #endif
  101.  
  102. #ifndef FWODGEOM_H
  103. #include "FWODGeom.h"
  104. #endif
  105.  
  106. // ----- Foundation Includes -----
  107.  
  108. #ifndef FWSTREAM_H
  109. #include "FWStream.h"
  110. #endif
  111.  
  112. // ----- OpenDoc Includes -----
  113.  
  114. #ifndef SOM_ODTransform_xh
  115. #include <Trnsform.xh>
  116. #endif
  117.  
  118. //========================================================================================
  119. // Runtime Information
  120. //========================================================================================
  121.  
  122. #ifdef FW_BUILD_MAC
  123. #pragma segment odfdrawshapes
  124. #endif
  125.  
  126. //========================================================================================
  127. // RunTime Info
  128. //========================================================================================
  129.  
  130. FW_DEFINE_AUTO(COvalShape)
  131. FW_DEFINE_CLASS_M1(COvalShape, CBoundedShape)
  132.  
  133. const FW_ClassTypeConstant LOvalShape = FW_TYPE_CONSTANT('s','h','o','v');
  134. FW_REGISTER_ARCHIVABLE_CLASS(LOvalShape, COvalShape, COvalShape::Read, 0, 0, CBaseShape::Write)
  135.  
  136. //========================================================================================
  137. // class COvalShape
  138. //========================================================================================
  139.  
  140. //----------------------------------------------------------------------------------------
  141. // COvalShape::COvalShape
  142. //----------------------------------------------------------------------------------------
  143.  
  144. COvalShape::COvalShape():
  145.     CBoundedShape(kOvalShape, kFrameOnly)
  146. {
  147.     FW_END_CONSTRUCTOR
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. // COvalShape::COvalShape
  152. //----------------------------------------------------------------------------------------
  153.  
  154. COvalShape::COvalShape(FW_CReadableStream& archive) :
  155.     CBoundedShape(archive)
  156. {    
  157.     FW_END_CONSTRUCTOR
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. // COvalShape::~COvalShape
  162. //----------------------------------------------------------------------------------------
  163.  
  164. COvalShape::~COvalShape()
  165. {
  166.     FW_START_DESTRUCTOR
  167. }
  168.  
  169. //----------------------------------------------------------------------------------------
  170. // COvalShape::OutlineShape
  171. //----------------------------------------------------------------------------------------
  172.  
  173. void COvalShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, const FW_CRect& rect)
  174. {
  175.     FW_CRect bounds(rect);
  176.     AdjustRectForPenSize(bounds, style.GetPenSize());
  177.     FW_COvalShape::RenderOval(gc,
  178.                               bounds,
  179.                               FW_kFrame,
  180.                               ink, style);
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. // COvalShape::RenderShape
  185. //----------------------------------------------------------------------------------------
  186.  
  187. void COvalShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
  188. {
  189.     FW_CRect rect = GetRectGeometry();
  190.     AdjustRectForPenSize(rect, GetPenSize());
  191.     
  192.     if (HasFillStyle())
  193.         FW_COvalShape::RenderOval(gc, rect, FW_kFill, fFillInk, fFillStyle);
  194.     
  195.     if (HasFrameStyle())
  196.         FW_COvalShape::RenderOval(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
  197. }
  198.  
  199. //----------------------------------------------------------------------------------------
  200. // COvalShape::HitTest
  201. //----------------------------------------------------------------------------------------
  202.  
  203. FW_Boolean COvalShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
  204. {    
  205.     FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  206.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  207.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  208.     frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
  209.  
  210.     FW_CRect bounds = GetRectGeometry();
  211.     AdjustRectForPenSize(bounds, GetPenSize());
  212.  
  213.     FW_COvalShape ovalShape(bounds, HasFillStyle() ? FW_kFill : FW_kFrame);
  214.     return ovalShape.HitTest(gc, mouse, FW_IntToFixed(2));
  215. }
  216.  
  217. //----------------------------------------------------------------------------------------
  218. // COvalShape::GetClipRegion
  219. //----------------------------------------------------------------------------------------
  220.  
  221. void COvalShape::GetClipRegion(Environment* ev, ODShape* clipRegion)
  222. {
  223.     FW_CRect bounds = GetRectGeometry();
  224.     AdjustRectForPenSize(bounds, GetPenSize());
  225.     
  226.     ODShape* ovalShape = ::FW_CreateOvalODShape(ev, bounds);
  227.     clipRegion->CopyFrom(ev, ovalShape);
  228.     ovalShape->Release(ev);
  229.     
  230.     if (FrameOnly())
  231.     {
  232.         bounds.Inset(GetPenSize(), GetPenSize());
  233.         ovalShape = ::FW_CreateOvalODShape(ev, bounds);
  234.         clipRegion->Subtract(ev, ovalShape);
  235.         ovalShape->Release(ev);
  236.     }
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. // COvalShape::CreateShapeOutline
  241. //----------------------------------------------------------------------------------------
  242.  
  243. ODShape* COvalShape::CreateShapeOutline(Environment *ev)
  244. {
  245.     FW_CRect bounds = GetRectGeometry();
  246.     AdjustRectForPenSize(bounds, GetPenSize());
  247.     
  248.     ODShape *dragRgn = ::FW_CreateOvalODShape(ev, bounds);        // We don't acquire it because we return it
  249.     
  250.     ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
  251.     
  252.     return dragRgn;
  253. }
  254.  
  255. //----------------------------------------------------------------------------------------
  256. // COvalShape::Read
  257. //----------------------------------------------------------------------------------------
  258.  
  259. void* COvalShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  260. {
  261. FW_UNUSED(type);
  262.     return FW_NEW(COvalShape, (stream));
  263. }
  264.  
  265.