home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / StCaptureView.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.1 KB  |  152 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "StCaptureView.h"
  20. #include "UGraphicGizmos.h"
  21.  
  22. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  23. //    Ñ    
  24. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  25.  
  26. StCaptureView::StCaptureView(LView& inView)
  27.     :    mOffscreenMacWorld(nil),
  28.         mView(inView)
  29. {
  30.     Init();
  31.  
  32.     SDimension16 theViewFrameSize;
  33.     mView.GetFrameSize(theViewFrameSize);
  34.     
  35.     mPortionToCapture.left        = mPortionToCapture.top = 0;
  36.     mPortionToCapture.right        = mPortionToCapture.left + theViewFrameSize.width;
  37.     mPortionToCapture.bottom    = mPortionToCapture.top  + theViewFrameSize.height;
  38. }
  39.  
  40. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  41. //    Ñ    
  42. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  43.  
  44. StCaptureView::StCaptureView(LView& inView, const Rect& inPortionToCapture)
  45.     :    mOffscreenMacWorld(nil),
  46.         mView(inView),
  47.         mPortionToCapture(inPortionToCapture)
  48. {
  49.     Init();
  50. }
  51.  
  52. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  53. //    Ñ    
  54. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  55.  
  56. void
  57. StCaptureView::Init()
  58. {
  59.     if (mView.IsActive())
  60.         mActive = triState_On;
  61.         
  62.     if (mView.IsEnabled())
  63.         mEnabled = triState_On;
  64.         
  65.     if (mView.IsVisible())
  66.         mVisible = triState_On;
  67. }
  68.  
  69. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  70. //    Ñ    
  71. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  72.  
  73. StCaptureView::~StCaptureView()
  74. {
  75. }
  76.  
  77. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  78. //    Ñ    
  79. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  80.  
  81. void StCaptureView::Capture(CGWorld& ioWorld)
  82. {
  83.     try
  84.     {
  85.         PlaceInSuperFrameAt(-mPortionToCapture.left, -mPortionToCapture.top, false);
  86.         ResizeFrameTo(
  87.                         mPortionToCapture.right  - mPortionToCapture.left,
  88.                         mPortionToCapture.bottom - mPortionToCapture.top,
  89.                         false);
  90.  
  91.         InstallOccupant(&mView, kAlignNone);
  92.  
  93.         Rect theSaveFrame = ioWorld.GetBounds();
  94.         if (!ioWorld.BeginDrawing())
  95.         {
  96.             throw memFullErr;
  97.         }
  98.  
  99.         mOffscreenMacWorld = ioWorld.GetMacGWorld();
  100.  
  101.         OutOfFocus(nil);
  102.         mView.Draw(nil);
  103.         OutOfFocus(nil);
  104.  
  105.         ioWorld.EndDrawing();
  106.         ioWorld.UpdateOrigin(topLeft(theSaveFrame));        
  107.  
  108.         RemoveOccupant();
  109.         mOffscreenMacWorld = nil;
  110.     }
  111.     catch (...)
  112.     {
  113.         RemoveOccupant();
  114.         mOffscreenMacWorld = nil;
  115.         throw;
  116.     }
  117. }
  118.  
  119. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  120. //    Ñ    
  121. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  122.  
  123. Boolean StCaptureView::EstablishPort(void)
  124. {
  125.     GrafPtr    thisPort = GetMacPort();
  126.     Boolean    portSet = (thisPort != nil);
  127.     if (portSet && (UQDGlobals::GetCurrentPort() != thisPort))
  128.         {
  129.         if (thisPort == (GrafPtr)mOffscreenMacWorld)
  130.             ::SetGWorld((GWorldPtr)thisPort, nil);
  131.         else
  132.             ::SetPort(thisPort);
  133.         }
  134.     return portSet;
  135. }
  136.  
  137. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  138. //    Ñ    
  139. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  140.  
  141. GrafPtr StCaptureView::GetMacPort(void) const
  142. {
  143.     GrafPtr    theMacPort;
  144.     if (mOffscreenMacWorld != nil)
  145.         theMacPort = (GrafPtr)mOffscreenMacWorld;
  146.     else
  147.         theMacPort = LView::GetMacPort();
  148.  
  149.     return theMacPort;
  150. }
  151.  
  152.