home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / OS / FWGraphx / Sources / FWRRcShp.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  10.2 KB  |  336 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWRRcShp.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWRRCSHP_H
  13. #include "FWRRcShp.h"
  14. #endif
  15.  
  16. #ifndef FWSHAPE_H
  17. #include "FWShape.h"
  18. #endif
  19.  
  20. #ifndef FWGC_H
  21. #include "FWGC.h"
  22. #endif
  23.  
  24. #ifndef FWDFAULT_H
  25. #include "FWDfault.h"
  26. #endif
  27.  
  28. #ifndef FWRECSHP_H
  29. #include "FWRecShp.h"
  30. #endif
  31.  
  32. #ifndef FWOVLSHP_H
  33. #include "FWOvlShp.h"
  34. #endif
  35.  
  36. #ifndef FWARCSHP_H
  37. #include "FWArcShp.h"
  38. #endif
  39.  
  40. #ifndef FWLINSHP_H
  41. #include "FWLinShp.h"
  42. #endif
  43.  
  44. #ifndef FWRGNSHP_H
  45. #include "FWRgnShp.h"
  46. #endif
  47.  
  48. #ifndef FWGRUTIL_H
  49. #include "FWGrUtil.h"
  50. #endif
  51.  
  52. // ----- OpenDoc Includes -----
  53.  
  54. #ifndef _TRNSFORM_
  55. #include <Trnsform.h>
  56. #endif
  57.  
  58. //==============================================================================
  59. //    •• RunTime Info
  60. //==============================================================================
  61.  
  62. #ifdef FW_BUILD_MAC
  63. #pragma segment fwgraphx
  64. #endif
  65.  
  66. //==============================================================================
  67. //    •• class FW_CRoundRectShape
  68. //==============================================================================
  69.  
  70. //------------------------------------------------------------------------------
  71. // FW_CRoundRectShape::FW_CRoundRectShape
  72. //------------------------------------------------------------------------------
  73.  
  74. FW_CRoundRectShape::FW_CRoundRectShape() :
  75.     FW_CShape()
  76. {
  77. }
  78.  
  79. //------------------------------------------------------------------------------
  80. // FW_CRoundRectShape::FW_CRoundRectShape
  81. //------------------------------------------------------------------------------
  82.  
  83. FW_CRoundRectShape::FW_CRoundRectShape(const FW_CRect& rect, const FW_CPoint& ovalSize) :
  84.     FW_CShape()
  85. {
  86.     SetRep(new FW_CRoundRectShapeRep(rect, ovalSize));
  87. }
  88.  
  89. //------------------------------------------------------------------------------
  90. // FW_CRoundRectShape::FW_CRoundRectShape
  91. //------------------------------------------------------------------------------
  92.  
  93. FW_CRoundRectShape::FW_CRoundRectShape(const FW_CRoundRectShape& other) :
  94.     FW_CShape(other)
  95. {
  96. }
  97.  
  98. //------------------------------------------------------------------------------
  99. // FW_CRoundRectShape::FW_CRoundRectShape
  100. //------------------------------------------------------------------------------
  101.  
  102. FW_CRoundRectShape::FW_CRoundRectShape(FW_CRoundRectShapeRep* rep) :
  103.     FW_CShape(rep)
  104. {
  105. }
  106.  
  107. //------------------------------------------------------------------------------
  108. // FW_CRoundRectShape::operator=
  109. //------------------------------------------------------------------------------
  110.  
  111. FW_CRoundRectShape& FW_CRoundRectShape::operator=(const FW_CRoundRectShape& other)
  112. {
  113.     SetRep(other.GetRep());
  114.     return *this;
  115. }
  116.  
  117. //------------------------------------------------------------------------------
  118. // FW_CRoundRectShape::operator=
  119. //------------------------------------------------------------------------------
  120.  
  121. FW_CRoundRectShape& FW_CRoundRectShape::operator=(FW_CRoundRectShapeRep* other)
  122. {
  123.     SetRep(other);
  124.     return *this;
  125. }
  126.  
  127. //------------------------------------------------------------------------------
  128. // FW_CRoundRectShape::operator FW_CRectShape
  129. //------------------------------------------------------------------------------
  130.  
  131. FW_CRoundRectShape::operator FW_CRectShape() const
  132. {    
  133.     FW_CRectShape rectShape(((FW_CShapeRep*)GetRep())->GetShapeBounds());
  134.     rectShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  135.     return rectShape;
  136. }
  137.  
  138. //------------------------------------------------------------------------------
  139. // FW_CRoundRectShape::operator FW_COvalShape
  140. //------------------------------------------------------------------------------
  141.  
  142. FW_CRoundRectShape::operator FW_COvalShape() const
  143. {    
  144.     FW_COvalShape ovalShape(((FW_CShapeRep*)GetRep())->GetShapeBounds());
  145.     ovalShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  146.     return ovalShape;
  147. }
  148.  
  149. //------------------------------------------------------------------------------
  150. // FW_CRoundRectShape::operator FW_CArcShape
  151. //------------------------------------------------------------------------------
  152.  
  153. FW_CRoundRectShape::operator FW_CArcShape() const
  154. {    
  155.     FW_CArcShape arcShape(((FW_CShapeRep*)GetRep())->GetShapeBounds(), 0, 0);
  156.     arcShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  157.     return arcShape;
  158. }
  159.  
  160. //------------------------------------------------------------------------------
  161. // FW_CRoundRectShape::operator FW_CLineShape
  162. //------------------------------------------------------------------------------
  163.  
  164. FW_CRoundRectShape::operator FW_CLineShape() const
  165. {    
  166.     FW_CRect rect = ((FW_CShapeRep*)GetRep())->GetShapeBounds();
  167.     FW_CLineShape lineShape(rect[FW_kTopLeft], rect[FW_kBotRight]);
  168.     lineShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  169.     return lineShape;
  170. }
  171.  
  172. //------------------------------------------------------------------------------
  173. // FW_CRoundRectShape::operator FW_CRegionShape
  174. //------------------------------------------------------------------------------
  175.  
  176. FW_CRoundRectShape::operator FW_CRegionShape() const
  177. {    
  178.     XMPShape *xmpShape = NULL;
  179.     
  180. #ifdef FW_BUILD_MAC
  181.     GrafPtr svPort;
  182.     ::GetPort(&svPort);
  183.     ::SetPort(gGraphicGlobales.gScratchWindow);
  184.     ::OpenRgn();
  185.     FW_SPlatformRect rect = ((FW_CShapeRep*)GetRep())->GetShapeBounds();
  186.     FW_SPlatformPoint ovalSize = ((FW_CRoundRectShapeRep*)GetRep())->GetOvalSize();
  187.     ::FrameRoundRect(&rect, ovalSize.h, ovalSize.v);
  188.     FW_PlatformRegion rgn = ::NewRgn();
  189.     ::CloseRgn(rgn);
  190.     xmpShape = ::NewXMPShape(rgn);
  191.     ::SetPort(svPort);
  192. #endif
  193.  
  194. #ifdef FW_BUILD_WIN
  195.     NotYetImplemented();
  196. #endif
  197.  
  198.     FW_CRegionShape regionShape(xmpShape);
  199.     regionShape->SetShapeFill(((FW_CShapeRep*)GetRep())->GetShapeFill());
  200.     return regionShape;
  201. }
  202.  
  203. //==============================================================================
  204. //    •• class FW_CRoundRectShapeRep
  205. //==============================================================================
  206.  
  207. //------------------------------------------------------------------------------
  208. //    • FW_CRoundRectShapeRep::FW_CRoundRectShapeRep
  209. //------------------------------------------------------------------------------
  210.  
  211. FW_CRoundRectShapeRep::FW_CRoundRectShapeRep() :
  212.     FW_CBoundedShapeRep(gGraphicGlobales.gRoundRect, FW_CRect(0,0,0,0)),
  213.     fOvalSize(0, 0)
  214. {
  215. }
  216.  
  217. //------------------------------------------------------------------------------
  218. //    • FW_CRoundRectShapeRep::FW_CRoundRectShapeRep
  219. //------------------------------------------------------------------------------
  220.  
  221. FW_CRoundRectShapeRep::FW_CRoundRectShapeRep(const FW_CRect& rect, const FW_CPoint& ovalSize) :
  222.     FW_CBoundedShapeRep(gGraphicGlobales.gRoundRect, rect),
  223.     fOvalSize(ovalSize)
  224. {
  225. }
  226.  
  227. //------------------------------------------------------------------------------
  228. //    • FW_CRoundRectShapeRep::~FW_CRoundRectShapeRep
  229. //------------------------------------------------------------------------------
  230.  
  231. FW_CRoundRectShapeRep::~FW_CRoundRectShapeRep()
  232. {
  233. }
  234.  
  235. //------------------------------------------------------------------------------
  236. //    • FW_CRoundRectShapeRep::Draw
  237. //------------------------------------------------------------------------------
  238.  
  239. void FW_CRoundRectShapeRep::Draw(FW_CGraphicContext* graphicContext)
  240. {    
  241.     FW_ShapeFills shapeFill = GetShapeFill();
  242.     
  243.     if (shapeFill == FW_kNullShape)
  244.         return;
  245.         
  246.     graphicContext->SelectInkAndStyle(GetShapeInk(), GetShapeStyle(), FW_kGeometricShape, shapeFill);
  247.  
  248.     FW_SPlatformRect rect = graphicContext->AsPlatformRect(fRect);
  249.     FW_SPlatformPoint ovalSize = graphicContext->AsPlatformPoint(fOvalSize);
  250.  
  251. #ifdef FW_BUILD_MAC
  252.     if (shapeFill == FW_kFramed)
  253.         ::FrameRoundRect(&rect, ovalSize.h, ovalSize.v);
  254.     else
  255.         ::PaintRoundRect(&rect, ovalSize.h, ovalSize.v);
  256. #endif
  257. #ifdef FW_BUILD_WIN
  258. #endif
  259. }
  260.  
  261. //------------------------------------------------------------------------------
  262. //    • FW_CRoundRectShapeRep::DrawRoundRect
  263. //------------------------------------------------------------------------------
  264.  
  265. void FW_CRoundRectShapeRep::DrawRoundRect(FW_CGraphicContext* graphicContext,
  266.                                         const FW_CRect& rect,
  267.                                         const FW_CPoint& ovalSize)
  268. {    
  269.     if (gGraphicGlobales.gRoundRect.fFill == FW_kNullShape)
  270.         return;
  271.  
  272.     graphicContext->SelectInkAndStyle(gGraphicGlobales.gRoundRect.fInk, gGraphicGlobales.gRoundRect.fStyle, FW_kGeometricShape, gGraphicGlobales.gRoundRect.fFill);
  273.  
  274.     FW_SPlatformRect qdRect = graphicContext->AsPlatformRect(rect);
  275.     FW_SPlatformPoint qdOvalSize = graphicContext->AsPlatformPoint(ovalSize);
  276.  
  277. #ifdef FW_BUILD_MAC
  278.     if (gGraphicGlobales.gRoundRect.fFill == FW_kFramed)
  279.         ::FrameRoundRect(&qdRect, qdOvalSize.h, qdOvalSize.v);
  280.     else
  281.         ::PaintRoundRect(&qdRect, qdOvalSize.h, qdOvalSize.v);
  282. #endif
  283. #ifdef FW_BUILD_WIN
  284. #endif
  285. }
  286.  
  287. //------------------------------------------------------------------------------
  288. //    • FW_CRoundRectShapeRep::Copy
  289. //------------------------------------------------------------------------------
  290.  
  291. FW_CRoundRectShape FW_CRoundRectShapeRep::Copy() const
  292. {
  293.     FW_CRoundRectShape roundRect(fRect, fOvalSize);
  294.     return roundRect;
  295. }
  296.  
  297. //------------------------------------------------------------------------------
  298. //    • FW_CRoundRectShapeRep::SetAsDefault
  299. //------------------------------------------------------------------------------
  300.  
  301. void FW_CRoundRectShapeRep::SetAsDefault() const
  302. {
  303.     SetDefaultProperties(gGraphicGlobales.gRoundRect);
  304. }
  305.  
  306. //------------------------------------------------------------------------------
  307. //    • FW_CRoundRectShapeRep::HitTest
  308. //------------------------------------------------------------------------------
  309.  
  310. FW_HitTestPart FW_CRoundRectShapeRep::HitTest(const FW_CPoint& test) const
  311. {
  312.     return FW_kOutside;
  313. }
  314.  
  315. //----------------------------------------------------------------------------------------
  316. //    • FW_CRoundRectShapeRep::Flatten
  317. //----------------------------------------------------------------------------------------
  318.  
  319. void FW_CRoundRectShapeRep::Flatten(FW_CWritableStream& stream)
  320. {
  321.     FW_CBoundedShapeRep::Flatten(stream);
  322.     fOvalSize.Flatten(stream);
  323. }
  324.  
  325. //----------------------------------------------------------------------------------------
  326. //    • FW_CRoundRectShapeRep::Unflatten
  327. //----------------------------------------------------------------------------------------
  328.  
  329. void FW_CRoundRectShapeRep::Unflatten(FW_CReadableStream& stream)
  330. {
  331.     FW_CBoundedShapeRep::Unflatten(stream);
  332.     fOvalSize.Unflatten(stream);
  333. }
  334.  
  335.  
  336.