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

  1. //========================================================================================
  2. //
  3. //    File:                FWScrCon.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 FWSCRCON_H
  13. #include "FWScrCon.h"
  14. #endif
  15.  
  16. #ifndef FWODGEOM_H
  17. #include "FWODGeom.h"
  18. #endif
  19.  
  20. #ifndef SLREGION_H
  21. #include "SLRegion.h"
  22. #endif
  23.  
  24. #ifndef SOM_ODShape_xh
  25. #include <Shape.xh>
  26. #endif
  27.  
  28. #if defined(FW_BUILD_MAC) && !defined(__WINDOWS__)
  29. #include "Windows.h"
  30. #endif
  31.  
  32. #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
  33. #include "QuickDraw.h"
  34. #endif
  35.  
  36. //========================================================================================
  37. //    RunTime Info
  38. //========================================================================================
  39.  
  40. #ifdef FW_BUILD_MAC
  41. #pragma segment FWGraphx_ScreenContext
  42. #endif
  43.  
  44. FW_DEFINE_AUTO(FW_CScreenContext)
  45.  
  46. //========================================================================================
  47. //    class FW_CScreenContext
  48. //========================================================================================
  49.  
  50. //----------------------------------------------------------------------------------------
  51. //    FW_CScreenContext::FW_CScreenContext
  52. //----------------------------------------------------------------------------------------
  53.  
  54. FW_CScreenContext::FW_CScreenContext(Environment* ev,
  55.                                        ODShape* clipShape,
  56.                                        ODTransform* transform) :
  57.     FW_CGraphicContext(ev),
  58.     fGraphicDevice(NULL)
  59. {
  60.     ODShape* odClipShape = NULL;
  61.  
  62.     FW_TRY
  63.     {
  64. #ifdef FW_BUILD_WIN
  65.         fDC = ::GetDC(NULL);
  66.         fGraphicDevice = FW_PrivGDev_CreateFromPlatformCanvas(ev, fDC);
  67.         FW_FailOnEvError(ev);
  68.         
  69.         int xScreen = ::GetSystemMetrics(SM_CXSCREEN);
  70.         int yScreen = ::GetSystemMetrics(SM_CYSCREEN);
  71.  
  72.         FW_CRect rect(FW_IntToFixed(0), FW_IntToFixed(0), FW_IntToFixed(xScreen), FW_IntToFixed(yScreen));
  73.         odClipShape = ::FW_NewODShape(ev, rect);
  74. #endif
  75. #ifdef FW_BUILD_MAC
  76.         GrafPtr savePort;
  77.         ::GetPort(&savePort);
  78.         ::OpenCPort(&fCGrafPort);
  79.         ::SetPort(savePort);
  80.  
  81.         fGraphicDevice = FW_PrivGDev_CreateFromPlatformCanvas(ev, (ODPlatformCanvas) &fCGrafPort);
  82.         FW_FailOnEvError(ev);
  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.         FW_PrivGDev_Release(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.     FW_PrivGDev_Release(fGraphicDevice);
  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.  
  142. //----------------------------------------------------------------------------------------
  143. //    FW_CScreenContext::Reset
  144. //----------------------------------------------------------------------------------------
  145.  
  146. void FW_CScreenContext::Reset()
  147. {
  148.     // Nothing to do [HLX] Am i sure ?
  149. }