home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CPatternPane.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  3.5 KB  |  129 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. #ifdef PowerPlant_PCH
  20. #include PowerPlant_PCH
  21. #endif
  22.  
  23. #include "CPatternPane.h"
  24. #include "UGraphicGizmos.h"
  25. #include "CSharedPatternWorld.h"
  26.  
  27. #include "StRegionHandle.h"
  28.  
  29. // ---------------------------------------------------------------------------
  30. //        Ñ CPatternPane
  31. // ---------------------------------------------------------------------------
  32.  
  33. CPatternPane::CPatternPane(LStream* inStream)
  34.     :    mOrientation(CSharedPatternWorld::eOrientation_Port),
  35.         mAdornWithBevel(false),
  36.         mDontFill(false),
  37.         mPatternWorld(nil),
  38.     
  39.         super(inStream)
  40. {
  41.     ThrowIfNil_(inStream);
  42.     
  43.     ResIDT    thePatternID;
  44.     Int16    theOrientation;
  45.     
  46.     *inStream >> thePatternID;
  47.     *inStream >> theOrientation;
  48.     *inStream >> mAdornWithBevel;
  49.     *inStream >> mDontFill;
  50.     
  51.     mOrientation = static_cast<CSharedPatternWorld::EPatternOrientation>(theOrientation);
  52.     
  53.     mPatternWorld = CSharedPatternWorld::CreateSharedPatternWorld(thePatternID);
  54.     ThrowIfNil_(mPatternWorld);
  55.     mPatternWorld->AddUser(this);
  56. }
  57.  
  58. // ---------------------------------------------------------------------------
  59. //        Ñ ~CPatternPane
  60. // ---------------------------------------------------------------------------
  61.  
  62. CPatternPane::~CPatternPane()
  63. {
  64.     mPatternWorld->RemoveUser(this);
  65. }
  66.  
  67. // ---------------------------------------------------------------------------
  68. //        Ñ AdornWithBevel
  69. // ---------------------------------------------------------------------------
  70.     
  71. void
  72. CPatternPane::AdornWithBevel(
  73.     const Rect& inFrameToBevel)
  74. {
  75.     UGraphicGizmos::BevelTintRect(inFrameToBevel, -1, 0x4000, 0x4000);
  76. }
  77.  
  78. // ---------------------------------------------------------------------------
  79. //        Ñ DrawSelf
  80. // ---------------------------------------------------------------------------
  81.     
  82. void
  83. CPatternPane::DrawSelf()
  84. {
  85.     Rect theLocalFrame;
  86.     
  87.     if (!CalcLocalFrameRect(theLocalFrame))
  88.         return;
  89.     
  90.     CGrafPtr    thePort;
  91.     Point        theAlignment;
  92.     
  93.     ::GetPort(&(GrafPtr)thePort);
  94.     
  95.     CSharedPatternWorld::CalcRelativePoint(this, mOrientation, theAlignment);
  96.  
  97.     // Fill the pane with the specified pattern
  98.     
  99.     if (mDontFill)
  100.     {
  101.         if (mAdornWithBevel)
  102.         {    
  103.             // If no filling is specified, but adorning is specified,
  104.             // then we must adjust clip region appropriately and then
  105.             // fill in order to ensure a properly patterned bevel.
  106.             
  107.             StClipRgnState    theClipRegionState;
  108.             StRegionHandle    theClipRegion;
  109.             Rect            theRect = theLocalFrame;
  110.             
  111.             theClipRegion    = theRect;
  112.             ::InsetRect(&theRect, 1, 1);
  113.             theClipRegion  -= theRect;
  114.             
  115.             ::SetClip(theClipRegion);
  116.  
  117.             mPatternWorld->Fill(thePort, theLocalFrame, theAlignment);
  118.         }
  119.     }
  120.     else
  121.     {
  122.         mPatternWorld->Fill(thePort, theLocalFrame, theAlignment);
  123.     }    
  124.  
  125.     // Now bevel the pane
  126.     
  127.     if (mAdornWithBevel)
  128.         AdornWithBevel(theLocalFrame);
  129. }