home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWScrCon.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  3.2 KB  |  141 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWScrCon.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWSCRCON_H
  13. #include "FWScrCon.h"
  14. #endif
  15.  
  16. #ifndef FWGDEV_H
  17. #include "FWGDev.h"
  18. #endif
  19.  
  20. #ifndef FWODGEOM_H
  21. #include "FWODGeom.h"
  22. #endif
  23.  
  24. #ifndef FWREGION_H
  25. #include "FWRegion.h"
  26. #endif
  27.  
  28. #ifndef SOM_ODShape_xh
  29. #include <Shape.xh>
  30. #endif
  31.  
  32. #if defined(FW_BUILD_MAC) && !defined(__WINDOWS__)
  33. #include "Windows.h"
  34. #endif
  35.  
  36. #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
  37. #include "QuickDraw.h"
  38. #endif
  39.  
  40. #if FW_LIB_EXPORT_PRAGMAS
  41. #pragma lib_export on
  42. #endif
  43.  
  44. #ifdef FW_BUILD_MAC
  45. #pragma segment FWGraphx_ScreenContext
  46. #endif
  47.  
  48. //========================================================================================
  49. //    class FW_CScreenContext
  50. //========================================================================================
  51.  
  52. //----------------------------------------------------------------------------------------
  53. //    FW_CScreenContext::FW_CScreenContext
  54. //----------------------------------------------------------------------------------------
  55.  
  56. FW_CScreenContext::FW_CScreenContext(Environment* ev,
  57.                                        ODShape* clipShape,
  58.                                        ODTransform* transform) :
  59.     FW_CGraphicContext(ev),
  60.     fGraphicDevice(NULL)
  61. {
  62.     ODShape* odClipShape = NULL;
  63.  
  64.     FW_TRY
  65.     {
  66. #ifdef FW_BUILD_WIN
  67.         fDC = ::GetDC(NULL);
  68.         fGraphicDevice = new FW_CGraphicDevice(ev, fDC);
  69.         
  70.         int xScreen = ::GetSystemMetrics(SM_CXSCREEN);
  71.         int yScreen = ::GetSystemMetrics(SM_CYSCREEN);
  72.  
  73.         FW_CRect rect(FW_IntToFixed(0), FW_IntToFixed(0), FW_IntToFixed(xScreen), FW_IntToFixed(yScreen));
  74.         odClipShape = ::FW_NewODShape(ev, rect);
  75. #endif
  76. #ifdef FW_BUILD_MAC
  77.         GrafPtr savePort;
  78.         ::GetPort(&savePort);
  79.         ::OpenCPort(&fCGrafPort);
  80.         ::SetPort(savePort);
  81.  
  82.         fGraphicDevice = new FW_CGraphicDevice(ev, (ODPlatformCanvas) &fCGrafPort);
  83.         
  84.         ODRgnHandle grayRgnCopy = ::FW_CopyRegion(GetGrayRgn());
  85.         odClipShape = ::FW_NewODShape(ev, grayRgnCopy);
  86. #endif
  87.         
  88.         if(clipShape != NULL)
  89.             odClipShape->Intersect(ev, clipShape);
  90.     
  91.         InitGraphicContext(fGraphicDevice,
  92.                             transform,
  93.                             odClipShape);
  94.     
  95.         odClipShape->Release(ev);        // we don't need it
  96.     }
  97.     FW_CATCH_BEGIN
  98.     FW_CATCH_EVERYTHING()
  99.     {
  100.         if(odClipShape != NULL)
  101.             odClipShape->Release(ev);
  102.             
  103.         delete fGraphicDevice;
  104.  
  105. #ifdef FW_BUILD_WIN
  106.         ::ReleaseDC(NULL, fDC);
  107. #endif
  108. #ifdef FW_BUILD_MAC
  109.         ::CloseCPort(&fCGrafPort);
  110. #endif
  111.  
  112.         FW_THROW_SAME();
  113.     }
  114.     FW_CATCH_END
  115.  
  116.     FW_END_CONSTRUCTOR
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120. //    FW_CScreenContext::~FW_CScreenContext
  121. //----------------------------------------------------------------------------------------
  122.  
  123. FW_CScreenContext::~FW_CScreenContext()
  124. {
  125.     FW_START_DESTRUCTOR
  126.  
  127.     // ----- Terminate the superclass
  128.     TerminateGraphicContext();
  129.  
  130.     // ----- Delete the device
  131.     fGraphicDevice->Release();
  132.  
  133.     // ----- It is now safe to clean up the platform device
  134. #ifdef FW_BUILD_WIN
  135.     ::ReleaseDC(NULL, fDC);
  136. #endif
  137. #ifdef FW_BUILD_MAC
  138.     ::CloseCPort(&fCGrafPort);
  139. #endif
  140. }
  141.