home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CProgressBar.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  7.6 KB  |  274 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 <LView.h>
  24. #include <UDrawingState.h>
  25.  
  26. #include "CProgressBar.h"
  27. #include "UGraphicGizmos.h"
  28.  
  29. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  30. //    Ñ
  31. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  32.  
  33. CProgressBar::CProgressBar(LStream* inStream)
  34.     :    LPane(inStream)
  35. {
  36.     *inStream >> mPatternID;
  37.     
  38.     mPatOffset = 0;
  39.     mValue = 0;
  40. }
  41.  
  42. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  43. //    Ñ
  44. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  45.  
  46. CProgressBar::~CProgressBar()
  47. {
  48.     if (mPolePattern != NULL)
  49.     ::DisposePixPat(mPolePattern);
  50. }
  51.  
  52. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  53. //    Ñ
  54. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  55.  
  56. void CProgressBar::FinishCreateSelf(void)
  57. {
  58.     mPolePattern = ::GetPixPat(mPatternID);
  59.     ThrowIfNULL_(mPolePattern);
  60.     
  61.     PixMapHandle theMap = (**mPolePattern).patMap;
  62.     mPatWidth = RectWidth((*theMap)->bounds);
  63.     
  64. //    SetValueRange(Range32T(0,100));
  65.     mValueRange = 100;
  66. }
  67.  
  68. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  69. //    Ñ
  70. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  71.  
  72. void CProgressBar::ActivateSelf(void)
  73. {
  74.     if (FocusExposed())
  75.         Refresh(); //Draw(NULL);
  76. }
  77.  
  78. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  79. //    Ñ
  80. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  81.  
  82. void CProgressBar::DeactivateSelf(void)
  83. {
  84.     if (FocusExposed())
  85.         Refresh(); //Draw(NULL);
  86. }
  87.  
  88. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  89. //    Ñ
  90. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  91.  
  92. void CProgressBar::GetActiveColors(
  93.     RGBColor& bodyColor,
  94.     RGBColor& barColor,
  95.     RGBColor& frameColor) const
  96. {
  97.     bodyColor.red = 0xCCCC;
  98.     bodyColor.green = 0xCCCC;
  99.     bodyColor.blue = 0xFFFF;
  100.     frameColor.red = 0;
  101.     frameColor.green = 0;
  102.     frameColor.blue = 0;
  103.     barColor.red = 0x4444;
  104.     barColor.green = 0x4444;
  105.     barColor.blue = 0x4444;
  106. }
  107.  
  108. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  109. //    Ñ
  110. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  111.  
  112. void CProgressBar::DrawSelf(void)
  113. {
  114.     StColorPenState theState;
  115.     theState.Normalize();    
  116.  
  117.     // Do not assume that we are drawing in a window. It may be
  118.     // an offscreen port.
  119.     GrafPtr    thePort;
  120.     ::GetPort(&thePort);
  121.  
  122.     AuxWinHandle theAuxHandle;
  123.     ::GetAuxWin(thePort, &theAuxHandle);
  124.     CTabHandle theColorTable = (**theAuxHandle).awCTable;
  125.  
  126.     RGBColor theWindowBack = UGraphicGizmos::FindInColorTable(theColorTable, wContentColor);
  127.  
  128.     RGBColor theBodyColor, theFrameColor, theBarColor;
  129. #if 0
  130.     if (IsActive())
  131. #endif
  132.         GetActiveColors(theBodyColor, theBarColor, theFrameColor);
  133. #if 0
  134.     else
  135.         {
  136.         // This looks ugly. It used to look "OK" in previous versions.
  137.         // However, drawing it with the active colors looks better.
  138.         GDHandle theGD = ::GetGDevice();
  139.         ::GetGray(theGD, &theWindowBack, &theFrameColor);
  140.         ::GetGray(theGD, &theWindowBack, &theBarColor);
  141.         ::GetGray(theGD, &theWindowBack, &theBodyColor);
  142.         }
  143. #endif
  144.         
  145. #if 0
  146.     RGBColor theBodyColor = { 0xCCCC, 0xCCCC, 0xFFFF };
  147.     RGBColor theFrameColor = { 0, 0, 0 };
  148.     RGBColor theBarColor = { 0x4444, 0x4444, 0x4444 };
  149.  
  150.     
  151.     if (!IsActive())
  152.         {
  153.         GDHandle theGD = ::GetGDevice();
  154.         ::GetGray(theGD, &theWindowBack, &theFrameColor);
  155.         ::GetGray(theGD, &theWindowBack, &theBarColor);
  156.         ::GetGray(theGD, &theWindowBack, &theBodyColor);
  157.         }
  158. #endif    
  159.     ::RGBForeColor(&theFrameColor);
  160.     ::RGBBackColor(&theWindowBack);
  161.  
  162.     Rect theFrame;
  163.     CalcLocalFrameRect(theFrame);
  164.     ::FrameRect(&theFrame);
  165.     ::InsetRect(&theFrame, 1, 1);
  166.  
  167.     if (GetValue() == eIndefinite)
  168.         DrawIndefiniteBar(theFrame);
  169.     else
  170.         DrawPercentageBar(theFrame, theBarColor, theBodyColor);
  171. }
  172.  
  173. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  174. //    Ñ
  175. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  176.  
  177. void CProgressBar::DrawIndefiniteBar(Rect& inBounds)
  178. {
  179.     Rect theBoundsCopy = inBounds;
  180.  
  181.     // Get our drawing port, and save the origin state.
  182.     // Don't assume we are onscreen (GetMacPort() would do that).
  183.     GrafPtr    thePort;
  184.     GetPort(&thePort);    
  185.     StPortOriginState theOriginSaver(thePort);
  186.  
  187.     // fake the pattern into thinking it's drawn somewhere else    
  188.     Point theOrigin;
  189.     theOrigin.h = thePort->portRect.left;
  190.     theOrigin.v = thePort->portRect.top;
  191.     ::SetOrigin(theOrigin.h - mPatOffset, theOrigin.v);
  192.  
  193.     // Adjust the drawing frame for the shift in port origin
  194.     ::OffsetRect(&theBoundsCopy, -mPatOffset, 0);
  195.  
  196.     // changing the origion means that we must offset the clip region
  197.     StClipRgnState theClipSaver;
  198.     ::ClipRect(&theBoundsCopy);
  199. //    StRegion        tempClipRgn;    // This doesn't work, but I don't know why.
  200. //    ::GetClip(tempClipRgn);
  201. //    ::OffsetRgn(tempClipRgn, - mPatOffset, 0);
  202. //    ::SetClip(tempClipRgn);
  203.  
  204.     ::FillCRect(&theBoundsCopy, mPolePattern);
  205.     mPatOffset = (mPatOffset + 1) % mPatWidth;
  206. }
  207.  
  208. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  209. //    Ñ
  210. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  211.  
  212. void CProgressBar::DrawPercentageBar(
  213.     Rect&                 inBounds,
  214.     const RGBColor&     inBarColor,
  215.     const RGBColor&     inBodyColor)
  216. {
  217.     Int32 theStart = 0;
  218.     Int32 theEnd = mValueRange;
  219.  
  220.     Int32 theValue = GetValue();
  221.     if (theValue < theStart)
  222.         theValue = theStart;
  223.     else if (theValue > theEnd)
  224.         theValue = theEnd;
  225.         
  226.     Int32 thePercentage = ((theValue * 100) / theEnd);
  227.     
  228.     Rect theBox = inBounds;
  229.     theBox.right = theBox.left + (thePercentage * RectWidth(inBounds)) / 100;
  230.     ::RGBForeColor(&inBarColor);
  231.     ::RGBBackColor(&inBodyColor);
  232.     ::PaintRect(&theBox);
  233.  
  234.     theBox.left = theBox.right;
  235.     theBox.right = inBounds.right;
  236.     ::RGBForeColor(&inBodyColor);
  237.     ::PmBackColor(eStdGrayBlack);
  238.  
  239.     ::PaintRect(&theBox);
  240. }
  241.  
  242. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  243. //    Ñ
  244. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  245.  
  246. Int32 CProgressBar::GetValue() const
  247. {
  248.     return mValue;
  249. }
  250.  
  251. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  252. //    Ñ
  253. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  254.  
  255. void CProgressBar::SetValue(Int32 inValue)
  256. {
  257.     if ((inValue != mValue) || (inValue == eIndefinite))
  258.         {
  259.         mValue = inValue;
  260.         if (FocusExposed())
  261.             Draw(NULL);
  262.         }
  263. }
  264.  
  265. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  266. //    Ñ
  267. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  268. #if 0
  269. void CProgressBar::SetValueRange(const Range32T& inRange)
  270. {
  271.     mValueRange = inRange;
  272. }
  273. #endif
  274.