home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / FWPoly.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.6 KB  |  209 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPoly.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWPOLY_H
  13. #include "FWPoly.h"
  14. #endif
  15.  
  16. #ifndef FWPOINT_H
  17. #include "FWPoint.h"
  18. #endif
  19.  
  20. #ifndef FWRECT_H
  21. #include "FWRect.h"
  22. #endif
  23.  
  24. // ----- Foundation Includes -----
  25.  
  26. #ifndef FWEXCEPT_H
  27. #include "FWExcept.h"
  28. #endif
  29.  
  30. #ifndef FWSTREAM_H
  31. #include "FWStream.h"
  32. #endif
  33.  
  34. #ifndef FWMEMORY_H
  35. #include "FWMemory.h"
  36. #endif
  37.  
  38. // ----- OpenDoc Includes -----
  39.  
  40. #ifndef _TRANSFORM_
  41. #include <Trnsform.xh>
  42. #endif
  43.  
  44. #ifdef FW_BUILD_MAC
  45. #pragma segment FWGraphics_Polygon
  46. #endif
  47.  
  48. //========================================================================================
  49. //    Template instantiation
  50. //========================================================================================
  51.  
  52. #include "FWGrRef.tpp"
  53.  
  54. FW_DEFINE_AUTO_TEMPLATE(FW_TGrRefPtr, FW_HPolygon)
  55.  
  56. #ifdef FW_USE_TEMPLATE_PRAGMAS
  57.  
  58. #pragma template_access public
  59. #pragma template FW_TGrRefPtr<FW_HPolygon>
  60.  
  61. #else
  62.  
  63. template class FW_TGrRefPtr<FW_HPolygon>;
  64.  
  65. #endif
  66.  
  67. //========================================================================================
  68. //    class FW_CPolygon
  69. //========================================================================================
  70.  
  71. FW_DEFINE_AUTO(FW_CPolygon)
  72.  
  73. //----------------------------------------------------------------------------------------
  74. //    FW_PrivAcquireGrRep
  75. //----------------------------------------------------------------------------------------
  76.  
  77. void FW_PrivAcquireGrRep(FW_HPolygon rep)
  78. {
  79.     if (rep != 0)
  80.         FW_PrivPolygon_Acquire(rep);
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. //    FW_PrivReleaseGrRep
  85. //----------------------------------------------------------------------------------------
  86.  
  87. void FW_PrivReleaseGrRep(FW_HPolygon rep)
  88. {
  89.     if (rep != 0)
  90.         FW_PrivPolygon_Release(rep);
  91. }
  92.  
  93. //----------------------------------------------------------------------------------------
  94. //    FW_CPolygon::FW_CPolygon
  95. //----------------------------------------------------------------------------------------
  96.  
  97. FW_CPolygon::FW_CPolygon()
  98. {
  99.     FW_END_CONSTRUCTOR
  100. }
  101.  
  102. //----------------------------------------------------------------------------------------
  103. //    FW_CPolygon::FW_CPolygon
  104. //----------------------------------------------------------------------------------------
  105.  
  106. FW_CPolygon::FW_CPolygon(long count, const FW_SPoint* points)
  107. {
  108.     FW_PlatformError error;
  109.     FW_HPolygon rep = FW_PrivPolygon_CreateFromPoints(count, points, &error);
  110.     FW_FailOnError(error);
  111.     SetRep(rep);
  112.     FW_END_CONSTRUCTOR
  113. }
  114.  
  115. //----------------------------------------------------------------------------------------
  116. //    FW_CPolygon::FW_CPolygon
  117. //----------------------------------------------------------------------------------------
  118.  
  119. FW_CPolygon::FW_CPolygon(FW_CReadableStream& stream)
  120. {
  121.     FW_PlatformError error;
  122.     FW_HPolygon rep = FW_PrivPolygon_Read(stream, &error);
  123.     FW_FailOnError(error);
  124.     SetRep(rep);
  125.     FW_END_CONSTRUCTOR
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    FW_CPolygon::FW_CPolygon
  130. //----------------------------------------------------------------------------------------
  131.  
  132. FW_CPolygon::FW_CPolygon(const FW_CPolygon& other) :
  133.     FW_TGrRefPtr<FW_HPolygon>(other)
  134. {
  135.     SetRep(other.fRep);
  136.     FW_END_CONSTRUCTOR
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. //    FW_CPolygon::~FW_CPolygon
  141. //----------------------------------------------------------------------------------------
  142.  
  143. FW_CPolygon::~FW_CPolygon()
  144. {
  145.     FW_START_DESTRUCTOR
  146. }
  147.  
  148. //----------------------------------------------------------------------------------------
  149. //    FW_CPolygon::Copy
  150. //----------------------------------------------------------------------------------------
  151.  
  152. FW_CPolygon    FW_CPolygon::Copy() const
  153. {
  154.     FW_PlatformError error;
  155.     FW_HPolygon rep = FW_PrivPolygon_Copy(fRep, &error);
  156.     FW_FailOnError(error);
  157.  
  158.     FW_CPolygon poly;
  159.     poly.SetRep(rep);
  160.     return poly;
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. //    FW_CPolygon::operator=
  165. //----------------------------------------------------------------------------------------
  166.  
  167. FW_CPolygon& FW_CPolygon::operator=(const FW_CPolygon& other)
  168. {
  169.     FW_TGrRefPtr<FW_HPolygon>::operator=(other);
  170.     return *this;
  171. }
  172.  
  173. //----------------------------------------------------------------------------------------
  174. //    FW_CPolygon::operator>>
  175. //----------------------------------------------------------------------------------------
  176.  
  177. FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_CPolygon& poly)
  178. {
  179.     FW_PlatformError error;
  180.     FW_HPolygon rep = FW_PrivPolygon_Read(stream, &error);
  181.     FW_FailOnError(error);
  182.     poly.SetRep(rep);
  183.     return stream;
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. //    FW_CPolygon::operator<<
  188. //----------------------------------------------------------------------------------------
  189.  
  190. FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_CPolygon& poly)
  191. {
  192.     FW_PlatformError error;
  193.     FW_PrivPolygon_Write(poly.fRep, stream, &error);
  194.     FW_FailOnError(error);
  195.     return stream;
  196. }
  197.  
  198. #ifdef FW_BUILD_WIN
  199.  
  200. //----------------------------------------------------------------------------------------
  201. // OpenDoc for Windows doesn't export ODPolygon::GetNContours, so we have to do it here
  202.  
  203. ODSLong    ODPolygon::GetNContours() const
  204. {
  205.     return _length > 0 ? _buf->nContours : 0;
  206. }
  207.  
  208. #endif
  209.