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 / FWGC.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  10.4 KB  |  321 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWGC.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 FWGC_H
  13. #include "FWGC.h"
  14. #endif
  15.  
  16. #ifndef FWGRUTIL_H
  17. #include "FWGrUtil.h"
  18. #endif
  19.  
  20. #ifndef SLGRGLOB_H
  21. #include "SLGrGlob.h"
  22. #endif
  23.  
  24. #ifndef FWFXMATH_H
  25. #include "FWFxMath.h"
  26. #endif
  27.  
  28. #ifndef SLREGION_H
  29. #include "SLRegion.h"
  30. #endif
  31.  
  32. #ifndef FWMAPING_H
  33. #include "FWMaping.h"
  34. #endif
  35.  
  36. #ifndef FWODGEOM_H
  37. #include "FWODGeom.h"
  38. #endif
  39.  
  40. #ifndef FWPRIDEB_H
  41. #include "FWPriDeb.h"
  42. #endif
  43.  
  44. // ----- OpenDoc Includes -----
  45.  
  46. #ifndef SOM_ODTransform_xh
  47. #include <Trnsform.xh>
  48. #endif
  49.  
  50. #ifndef SOM_ODShape_xh
  51. #include <Shape.xh>
  52. #endif
  53.  
  54. #ifndef SOM_ODCanvas_xh
  55. #include <Canvas.xh>
  56. #endif
  57.  
  58. //========================================================================================
  59. //    RunTime Info
  60. //========================================================================================
  61.  
  62. #ifdef FW_BUILD_MAC
  63. #pragma segment FW_GRTransformContextSegment
  64. #endif
  65.  
  66. //========================================================================================
  67. //    class FW_CGraphicContext
  68. //========================================================================================
  69.  
  70. FW_DEFINE_AUTO(FW_CGraphicContext)
  71.  
  72. //----------------------------------------------------------------------------------------
  73. //    FW_CGraphicContext::FW_CGraphicContext
  74. //----------------------------------------------------------------------------------------
  75.  
  76. FW_CGraphicContext::FW_CGraphicContext(Environment* ev)
  77. {
  78.     FW_PrivGC_Clear(ev, *this);
  79.     FW_END_CONSTRUCTOR
  80. }
  81.  
  82. //----------------------------------------------------------------------------------------
  83. //    FW_CGraphicContext::InitGraphicContext
  84. //----------------------------------------------------------------------------------------
  85. //    clipShape is in content coordinate
  86.  
  87. FW_DECLARE_THROW_POINT (FW_CGraphicContext_InitGraphicContext);
  88.  
  89. void FW_CGraphicContext::InitGraphicContext(FW_HGDevice graphicDevice,
  90.                                             ODTransform* transform,
  91.                                             ODShape* clipShape)
  92. {
  93.     FW_PrivGC_Initialize(fEnvironment, *this, graphicDevice, transform, clipShape);
  94.     FW_FailOnEvError(fEnvironment);
  95. }
  96.  
  97. //----------------------------------------------------------------------------------------
  98. //    FW_CGraphicContext::PrivReset
  99. //----------------------------------------------------------------------------------------
  100. //    Used after AutoScroll
  101.  
  102. void FW_CGraphicContext::PrivReset(ODTransform* transform,
  103.                                 ODShape* clipShape)
  104. {
  105.     FW_PrivGC_ChangeClipAndTransform(fEnvironment, *this, transform, clipShape);
  106.     FW_FailOnEvError(fEnvironment);
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    FW_CGraphicContext::TerminateGraphicContext
  111. //----------------------------------------------------------------------------------------
  112.  
  113. void FW_CGraphicContext::TerminateGraphicContext()
  114. {
  115.     FW_PrivGC_Terminate(fEnvironment, *this);
  116.     FW_FailOnEvError(fEnvironment);
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120. //    FW_CGraphicContext::~FW_CGraphicContext
  121. //----------------------------------------------------------------------------------------
  122.  
  123. FW_CGraphicContext::~FW_CGraphicContext()
  124. {
  125.     FW_START_DESTRUCTOR
  126.  
  127.     TerminateGraphicContext();
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //    FW_CGraphicContext::SetMapping
  132. //----------------------------------------------------------------------------------------
  133.  
  134. void FW_CGraphicContext::SetMapping(const FW_SMapping& newMapping)
  135. {
  136.     FW_PrivGC_SetMapping(fEnvironment, *this, newMapping);
  137.     FW_FailOnEvError(fEnvironment);
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    FW_CGraphicContext::GetMapping
  142. //----------------------------------------------------------------------------------------
  143.  
  144. void FW_CGraphicContext::GetMapping(FW_CMapping& mapping) const
  145. {
  146.     mapping = fMapping;
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. //    FW_CGraphicContext::SetClip
  151. //----------------------------------------------------------------------------------------
  152.  
  153. void FW_CGraphicContext::SetClip(ODShape* odShape)                    // a copy of odShape is used
  154.     FW_PrivGC_SetClip(fEnvironment, *this, odShape); 
  155.     FW_FailOnEvError(fEnvironment);
  156. }
  157.     
  158. //----------------------------------------------------------------------------------------
  159. //    FW_CGraphicContext::GetClipRect
  160. //----------------------------------------------------------------------------------------
  161.  
  162. void FW_CGraphicContext::GetClipRect(FW_SRect& clipRect) const
  163.     FW_PrivGC_GetClipRect(fEnvironment, *this, clipRect); 
  164.     FW_FailOnEvError(fEnvironment);
  165. }
  166.  
  167. //----------------------------------------------------------------------------------------
  168. //    FW_CGraphicContext::SetClipRect
  169. //----------------------------------------------------------------------------------------
  170.  
  171. void FW_CGraphicContext::SetClipRect(const FW_SRect& clipRect)
  172.     FW_PrivGC_SetClipRect(fEnvironment, *this, clipRect); 
  173.     FW_FailOnEvError(fEnvironment);
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    FW_CGraphicContext::LogicalToDevice
  178. //----------------------------------------------------------------------------------------
  179.  
  180. FW_CPlatformPoint FW_CGraphicContext::LogicalToDevice(FW_Fixed xSize, FW_Fixed ySize) const
  181. {
  182.     FW_CPlatformPoint ptResult;
  183.     FW_PrivGC_LogicalToDeviceSize(fEnvironment, *this, xSize, ySize, ptResult);
  184.     FW_FailOnEvError(fEnvironment);
  185.     return ptResult;
  186. }
  187.  
  188. //----------------------------------------------------------------------------------------
  189. //    FW_CGraphicContext::LogicalToDevice
  190. //----------------------------------------------------------------------------------------
  191.  
  192. FW_CPlatformPoint FW_CGraphicContext::LogicalToDevice(const FW_CPoint& point) const
  193. {
  194.     FW_CPlatformPoint plfmPoint;
  195.     FW_PrivGC_LogicalToDevicePoint(fEnvironment, *this, point, plfmPoint);
  196.     FW_FailOnEvError(fEnvironment);
  197.     return plfmPoint;
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. //    FW_CGraphicContext::LogicalToDevice
  202. //----------------------------------------------------------------------------------------
  203.  
  204. FW_CPlatformRect FW_CGraphicContext::LogicalToDevice(const FW_CRect& rect) const
  205. {
  206.     FW_CPlatformRect plfmRect;
  207.     FW_PrivGC_LogicalToDeviceRect(fEnvironment, *this, rect, plfmRect);
  208.     FW_FailOnEvError(fEnvironment);
  209.     return plfmRect;
  210. }
  211.  
  212. //----------------------------------------------------------------------------------------
  213. //    FW_CGraphicContext::LogicalToDevice
  214. //----------------------------------------------------------------------------------------
  215.  
  216. ODShape* FW_CGraphicContext::LogicalToDevice(ODShape* shape) const
  217. {
  218.     ODShape* result = FW_PrivGC_LogicalToDeviceShape(fEnvironment, *this, shape);
  219.     FW_FailOnEvError(fEnvironment);
  220.     return result;
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. //    FW_CGraphicContext::DeviceToLogical
  225. //----------------------------------------------------------------------------------------
  226.  
  227. FW_CPoint FW_CGraphicContext::DeviceToLogical(FW_PlatformCoordinate xSize, FW_PlatformCoordinate ySize) const
  228. {
  229.     FW_CPoint ptResult;
  230.     FW_PrivGC_DeviceToLogicalSize(fEnvironment, *this, xSize, ySize, ptResult);
  231.     FW_FailOnEvError(fEnvironment);
  232.     return ptResult;
  233. }
  234.  
  235. //----------------------------------------------------------------------------------------
  236. //    FW_CGraphicContext::DeviceToLogical
  237. //----------------------------------------------------------------------------------------
  238.  
  239. FW_CPoint FW_CGraphicContext::DeviceToLogical(const FW_CPlatformPoint& point) const
  240. {
  241.     FW_CPoint pt;
  242.     FW_PrivGC_DeviceToLogicalPoint(fEnvironment, *this, point, pt);
  243.     FW_FailOnEvError(fEnvironment);
  244.     return pt;
  245. }
  246.  
  247. //----------------------------------------------------------------------------------------
  248. //    FW_CGraphicContext::DeviceToLogical
  249. //----------------------------------------------------------------------------------------
  250.  
  251. FW_CRect FW_CGraphicContext::DeviceToLogical(const FW_CPlatformRect& rect) const
  252. {
  253.     FW_CRect rectResult;
  254.     FW_PrivGC_DeviceToLogicalRect(fEnvironment, *this, rect, rectResult);
  255.     FW_FailOnEvError(fEnvironment);
  256.     return rectResult;
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    FW_CGraphicContext::DeviceToLogical
  261. //----------------------------------------------------------------------------------------
  262.  
  263. ODShape* FW_CGraphicContext::DeviceToLogical(ODShape* shape) const
  264. {
  265.     ODShape* result = FW_PrivGC_DeviceToLogicalShape(fEnvironment, *this, shape);
  266.     FW_FailOnEvError(fEnvironment);
  267.     return result;
  268. }
  269.  
  270. //----------------------------------------------------------------------------------------
  271. //    FW_CGraphicContext::AcquireClip
  272. //----------------------------------------------------------------------------------------
  273.  
  274. ODShape* FW_CGraphicContext::AcquireClip() const
  275. {
  276.     ODShape* shape = FW_PrivGC_GetClip(fEnvironment, *this);
  277.     FW_FailOnEvError(fEnvironment);
  278.     return shape;
  279. }
  280.  
  281. //========================================================================================
  282. //    class FW_CSaveRestoreContext
  283. //========================================================================================
  284.  
  285. FW_DEFINE_AUTO(FW_CSaveRestoreContext)
  286.  
  287. //----------------------------------------------------------------------------------------
  288. //    FW_CSaveRestoreContext::FW_CSaveRestoreContext
  289. //----------------------------------------------------------------------------------------
  290.  
  291. FW_CSaveRestoreContext::FW_CSaveRestoreContext(FW_CGraphicContext& gc) :
  292.     fGC(gc),
  293.     fSuspendResume(NULL)
  294. {
  295.     FW_ASSERT(&gc == FW_PrivGC_GetCurrent(gc.GetEnvironment()));    
  296.     
  297.     FW_PlatformError error;
  298.     fSuspendResume = FW_PrivGDev_Suspend(gc.fGraphicDevice, &error);
  299.     FW_FailOnError(error);
  300.  
  301.     FW_END_CONSTRUCTOR
  302. }
  303.     
  304. //----------------------------------------------------------------------------------------
  305. //    FW_CSaveRestoreContext::FW_CSaveRestoreContext
  306. //----------------------------------------------------------------------------------------
  307.  
  308. FW_CSaveRestoreContext::~FW_CSaveRestoreContext()
  309. {
  310.     FW_START_DESTRUCTOR
  311.     FW_PlatformError error;
  312.     
  313.     // ----- ATTENTION: I don't own fSuspendResume so I don't delete it -----
  314.     if (fSuspendResume)
  315.          FW_PrivGDev_Resume(fGC.fGraphicDevice, fSuspendResume, &error);
  316.     // [HLX] What do I do with the error
  317. }
  318.