home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CPatternButton.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  7.4 KB  |  264 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 <UGAColorRamp.h>
  24.  
  25. #include "CPatternButton.h"
  26. #include "UGraphicGizmos.h"
  27. #include "UGAAppearance.h"
  28. #include "CSharedPatternWorld.h"
  29.  
  30. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  31. //    Ñ    
  32. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  33.  
  34. CPatternButton::CPatternButton(LStream* inStream)
  35.     :    CToolbarButton(inStream)
  36. {
  37.     mMouseInFrame = false;
  38.  
  39.     ResIDT thePatternID;
  40.     *inStream >> thePatternID;
  41.     
  42.     *inStream >> mOrientation;
  43.     
  44.     mPatternWorld = CSharedPatternWorld::CreateSharedPatternWorld(thePatternID);
  45.     ThrowIfNULL_(mPatternWorld);
  46.     mPatternWorld->AddUser(this);
  47. }
  48.  
  49. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  50. //    Ñ    
  51. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  52.  
  53. CPatternButton::~CPatternButton()
  54. {
  55.     mPatternWorld->RemoveUser(this);
  56. }
  57.  
  58. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  59. //    Ñ    DrawButtonContent
  60. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  61.     
  62. void CPatternButton::DrawButtonContent(void)
  63. {
  64.     CGrafPtr thePort;
  65.     ::GetPort(&(GrafPtr)thePort);
  66.     
  67.     Rect theFrame = mCachedButtonFrame;
  68.     Point theAlignment;
  69.     
  70.     CalcOrientationPoint(theAlignment);
  71.     mPatternWorld->Fill(thePort, theFrame, theAlignment);
  72.  
  73.     ::InsetRect(&theFrame, 2, 2);
  74.  
  75.     if (IsActive() && IsEnabled())
  76.         {
  77.         if (IsTrackInside() || (!IsBehaviourButton() && (mValue == Button_On)))
  78.             {
  79.             DrawButtonHilited();
  80.             }
  81.         else if (IsMouseInFrame())
  82.             {
  83.             DrawButtonNormal();
  84.             }
  85.         }
  86. }
  87.  
  88. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  89. //    Ñ    
  90. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  91.  
  92. void CPatternButton::DrawButtonGraphic(void)
  93. {
  94.     ResIDT theSaveID = GetGraphicID();
  95.     ResIDT theNewID = theSaveID;
  96.  
  97.     if (IsEnabled() && IsActive())
  98.         {
  99.         if (!IsBehaviourButton() && (GetValue() == Button_On))
  100.         {
  101.             // do something different if IsTrackInside()
  102.             theNewID += 2;
  103.         }
  104.         else if (IsTrackInside())
  105.             theNewID += 3;
  106.         else if (IsMouseInFrame())
  107.             theNewID += 2;
  108.         }
  109.     else
  110.         theNewID += 1;
  111.  
  112.     SetGraphicID(theNewID);    
  113.     CToolbarButton::DrawButtonGraphic();
  114.     SetGraphicID(theSaveID);
  115. }
  116.  
  117. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  118. //    Ñ    
  119. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  120.  
  121. void CPatternButton::DrawButtonTitle(void)
  122. {
  123.     StColorPenState::Normalize();
  124.         
  125.     if (IsTrackInside() || GetValue() == Button_On)
  126.     {
  127.         ::RGBForeColor(&UGAColorRamp::GetWhiteColor());
  128.         ::OffsetRect(&mCachedTitleFrame, 1, 1);
  129.     }
  130.     else if (!IsActive() || !IsEnabled())
  131.     {
  132. //        ::RGBForeColor(&UGAColorRamp::GetColor(colorRamp_Gray7));
  133.         ::TextMode(grayishTextOr);
  134.     }
  135.  
  136.     UGraphicGizmos::PlaceStringInRect(mTitle, mCachedTitleFrame, teCenter, teCenter);
  137. }
  138.  
  139. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  140. //    Ñ    
  141. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  142.  
  143. void CPatternButton::MouseEnter(
  144.     Point                /* inPortPt */,
  145.     const EventRecord&    /* inMacEvent */)
  146. {
  147.     mMouseInFrame = true;
  148.     if (IsActive() && IsEnabled())
  149.         Draw(NULL);
  150. }
  151.  
  152. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  153. //    Ñ    
  154. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  155.  
  156. void CPatternButton::MouseWithin(
  157.     Point                /* inPortPt */,
  158.     const EventRecord&    /* inMacEvent */)
  159. {
  160.     // Nothing to do for now
  161. }
  162.  
  163. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  164. //    Ñ    
  165. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  166.  
  167. void CPatternButton::MouseLeave(void)
  168. {
  169.     mMouseInFrame = false;
  170.     if (IsActive() && IsEnabled())
  171.         Draw(NULL);
  172. }
  173.  
  174. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  175. //    Ñ    
  176. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  177.  
  178. void CPatternButton::CalcOrientationPoint(Point& outPoint)
  179. {
  180.     // the downward scale from 32 to 16 bit coordinate spaces
  181.     // in converting from SPoint32 to plain old Point
  182.     // is ok because we are guaranteed to be in bounds since we
  183.     // wont be drawing if we cant FocusExposed().
  184.  
  185.     SPoint32 theFrameLocation;
  186.     switch (mOrientation)
  187.         {
  188.         case CSharedPatternWorld::eOrientation_Self:
  189.             {
  190.             GetFrameLocation(theFrameLocation);
  191.             outPoint.h = theFrameLocation.h;
  192.             outPoint.v = theFrameLocation.v;
  193.             PortToLocalPoint(outPoint);
  194.             }
  195.             break;
  196.             
  197.         case CSharedPatternWorld::eOrientation_Superview:
  198.             {
  199.             mSuperView->GetFrameLocation(theFrameLocation);
  200.             outPoint.h = -theFrameLocation.h;
  201.             outPoint.v = -theFrameLocation.v;
  202.             PortToLocalPoint(outPoint);
  203.             }
  204.             break;
  205.             
  206.         case CSharedPatternWorld::eOrientation_Port:
  207.             {
  208.             mSuperView->GetPortOrigin(outPoint);
  209.             }
  210.             break;
  211.         }
  212. }
  213.  
  214. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  215. //    Ñ    DrawButtonNormal
  216. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  217. //    Draw button AGA bevel border
  218.  
  219. void CPatternButton::DrawButtonNormal()
  220. {
  221.     // Ñ Setup a device loop so that we can handle drawing at the correct bit depth
  222.     StDeviceLoop    theLoop ( mCachedButtonFrame );
  223.     Int16            depth;
  224.  
  225.     // Draw face of button first            
  226.     while ( theLoop.NextDepth ( depth )) 
  227.         if ( depth >= 4 )        // don't do anything for black and white
  228.             {
  229.             Rect rect = mCachedButtonFrame;
  230.             ::InsetRect(&rect, 1, 1);
  231.             UGraphicGizmos::LowerRoundRectColorVolume(rect, 4, 4,
  232.                                                       UGAAppearance::sGAHiliteContentTint);
  233.             }
  234.  
  235.     // Now draw GA button bevel
  236.     UGAAppearance::DrawGAButtonBevelTint(mCachedButtonFrame);
  237. }
  238.  
  239. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  240. //    Ñ    DrawButtonHilited
  241. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  242. //    Draw button AGA "mouse-down" look
  243.  
  244. void CPatternButton::DrawButtonHilited()
  245. {
  246.     // Ñ Setup a device loop so that we can handle drawing at the correct bit depth
  247.     StDeviceLoop    theLoop ( mCachedButtonFrame );
  248.     Int16            depth;
  249.  
  250.     Rect frame = mCachedButtonFrame;
  251.  
  252.     // Draw face of button first
  253.     while ( theLoop.NextDepth ( depth )) 
  254.         if ( depth >= 4 )        // don't do anything for black and white
  255.             {
  256.             ::InsetRect(&frame, 1, 1);
  257.             // Do we need to do this very slight darkening?
  258.             UGraphicGizmos::LowerRoundRectColorVolume(frame, 4, 4, UGAAppearance::sGASevenGrayLevels);
  259.             ::InsetRect(&frame, -1, -1);
  260.             }
  261.  
  262.     // Now draw GA pressed button bevel
  263.     UGAAppearance::DrawGAButtonPressedBevelTint(mCachedButtonFrame);
  264. }