home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / UStClasses.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  2.9 KB  |  106 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. //
  20. // File: UStClasses.cp
  21. //
  22. // This file contains a couple of stack-based save/restore classes
  23. // 
  24.  
  25. #include "UStClasses.h"
  26.  
  27.  
  28. //======================================================================================
  29. #pragma mark * StSetResAttrs
  30.  
  31. //
  32. //     Constructor. Set the resource handle attributes to the specified attributes. If
  33. //    inAddAttrs is true, add the specified attributes to the current attributes; otherwise
  34. //    reset the attributes completely.
  35. //
  36. StSetResAttrs::StSetResAttrs(Handle inResourceH, short inResAttrs, Boolean inAddAttrs) {
  37.  
  38.     Assert_(inResourceH != nil);
  39.     
  40.     mResourceH = nil;
  41.     
  42.     mSavedAttrs = ::GetResAttrs(inResourceH);
  43.     ThrowIfResError_();
  44.     ::SetResAttrs(inResourceH, inAddAttrs ? (mSavedAttrs | inResAttrs) : inResAttrs);
  45.     ThrowIfResError_();
  46.     mResourceH = inResourceH;
  47. }
  48.  
  49.  
  50. //
  51. // Destructor
  52. //
  53. StSetResAttrs::~StSetResAttrs(void) {
  54.  
  55.     if ( mResourceH ) {
  56.         ::SetResAttrs(mResourceH, mSavedAttrs);
  57.         OSErr theErr = ::ResError();
  58.         Assert_(theErr == noErr);
  59.     }
  60. }
  61.  
  62. //======================================================================================
  63. #pragma mark * StExcludeVisibleRgn
  64.  
  65. //
  66. // Constructor.
  67. //
  68. // Exclude the specified port rectangle from the current visible region.
  69. //
  70. StExcludeVisibleRgn::StExcludeVisibleRgn(LPane *inPane) {
  71.  
  72.     mGrafPtr = nil;
  73.     
  74.     Assert_(inPane != nil);
  75.     FailNIL_(mSaveVisRgn = ::NewRgn());
  76.     
  77.     Rect portFrame;
  78.     GrafPtr port = inPane->GetMacPort();
  79.     inPane->CalcPortFrameRect(portFrame);
  80.     StRegion tempRgn(portFrame);
  81.     ::CopyRgn(port->visRgn, mSaveVisRgn);
  82.     ::DiffRgn(port->visRgn, tempRgn, port->visRgn);
  83.     
  84.     mGrafPtr = port;
  85.     mSavePortOrigin = topLeft(mGrafPtr->portRect);
  86. }
  87.  
  88.  
  89. //
  90. // Destructor.
  91. //
  92. StExcludeVisibleRgn::~StExcludeVisibleRgn(void) {
  93.  
  94.     if ( mGrafPtr != nil ) {
  95.         Point deltaOrigin = topLeft(mGrafPtr->portRect);
  96.         deltaOrigin.h -= mSavePortOrigin.h;
  97.         deltaOrigin.v -= mSavePortOrigin.v;
  98.         if ( (deltaOrigin.h != 0) || (deltaOrigin.v != 0) ) {
  99.             ::OffsetRgn(mSaveVisRgn, deltaOrigin.h, deltaOrigin.v);
  100.         }
  101.         RgnHandle tempRgn = mGrafPtr->visRgn;
  102.         mGrafPtr->visRgn = mSaveVisRgn;
  103.         ::DisposeRgn(tempRgn);
  104.     }
  105. }
  106.