home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CProgressCaption.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  5.4 KB  |  207 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. //    CProgressCaption.cp
  21. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  22.  
  23. #include "CProgressCaption.h"
  24.  
  25. #ifdef PowerPlant_PCH
  26. #include PowerPlant_PCH
  27. #endif
  28.  
  29. #include <URegions.h>
  30. #include "UGraphicGizmos.h"
  31.  
  32. #pragma mark public
  33.  
  34. enum {eNoColorSet = -1};
  35.  
  36. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  37. //    Ñ
  38. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  39.  
  40. CProgressCaption::CProgressCaption(LStream* inStream)
  41.     :    CProgressBar(inStream)
  42. {
  43.     inStream->ReadPString(mText);
  44. //    *inStream >> mText;
  45.     *inStream >> mBoundedTraitsID;
  46.     *inStream >> mIndefiniteTraitsID;
  47.     *inStream >> mHiddenTraitsID;
  48.     *inStream >> mEraseColor;
  49.     SetHidden();
  50. }
  51.  
  52. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  53. //    Ñ
  54. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  55.  
  56. CProgressCaption::~CProgressCaption()
  57. {
  58. }
  59.  
  60. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  61. //    Ñ
  62. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  63.  
  64. StringPtr CProgressCaption::GetDescriptor(
  65.     Str255    outDescriptor) const
  66. {
  67.     return LString::CopyPStr(mText, outDescriptor);
  68. }
  69.  
  70.  
  71. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  72. //    Ñ
  73. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  74.  
  75. void CProgressCaption::SetDescriptor(ConstStringPtr    inDescriptor)
  76. {
  77.     if (inDescriptor == NULL)
  78.         mText = "\p";
  79.     else
  80.         mText = inDescriptor;
  81.     
  82.     if (FocusExposed())
  83.         Draw(NULL);
  84. }
  85.  
  86. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  87. //    Ñ
  88. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  89.  
  90. void CProgressCaption::SetDescriptor(const char* inCDescriptor)
  91. {
  92.     if (inCDescriptor == NULL)
  93.         mText = "\p";
  94.     else
  95.         mText = inCDescriptor;
  96.  
  97.     if (FocusExposed())
  98.         Draw(NULL);
  99. }
  100.  
  101. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  102. //    Ñ
  103. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  104.  
  105. void CProgressCaption::Draw(RgnHandle inSuperDrawRgnH)
  106. {
  107.     Rect theFrame;
  108.     if ((mVisible == triState_On) && CalcPortFrameRect(theFrame) &&
  109.             ((inSuperDrawRgnH == nil) || RectInRgn(&theFrame, inSuperDrawRgnH)) && FocusDraw())
  110.         {
  111.         PortToLocalPoint(topLeft(theFrame));    // Get Frame in Local coords
  112.         PortToLocalPoint(botRight(theFrame));
  113.  
  114.         if (ExecuteAttachments(msg_DrawOrPrint, &theFrame))
  115.             {
  116.             Boolean bDidDraw = false;
  117.  
  118.             StColorPenState thePenSaver;
  119.             StColorPenState::Normalize();
  120.             
  121.             // Fail safe offscreen drawing
  122.             StValueChanger<EDebugAction> okayToFail(gDebugThrow, debugAction_Nothing);
  123.             try
  124.                 {            
  125.                 LGWorld theOffWorld(theFrame, 0, useTempMem);
  126.  
  127.                 if (!theOffWorld.BeginDrawing())
  128.                     throw memFullErr;
  129.                     
  130.                 DrawSelf();
  131.                     
  132.                 theOffWorld.EndDrawing();
  133.                 theOffWorld.CopyImage(GetMacPort(), theFrame, srcCopy);
  134.                 bDidDraw = true;
  135.                 }
  136.             catch (...)
  137.                 {
  138.                 //     & draw onscreen
  139.                 }
  140.                 
  141.             if (!bDidDraw)
  142.                 DrawSelf();
  143.             }
  144.         }
  145. }
  146.  
  147. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  148. //    Ñ
  149. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  150.  
  151. void CProgressCaption::GetActiveColors(RGBColor& bodyColor, RGBColor& barColor, RGBColor& frameColor) const
  152. {
  153.     CProgressBar::GetActiveColors(bodyColor, barColor, frameColor);
  154.     barColor.red = 0x8888;
  155.     barColor.green = 0x8888;
  156.     barColor.blue = 0xFFFF;
  157. }
  158.  
  159. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  160. //    Ñ
  161. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  162.  
  163. void CProgressCaption::DrawSelf(void)
  164. {
  165.     Rect theFrame;
  166.     CalcLocalFrameRect(theFrame);
  167.  
  168.     ResIDT theTraitsID;
  169.     switch (GetValue())
  170.     {
  171.         case eIndefinite:
  172.             theTraitsID = mIndefiniteTraitsID;
  173.             break;
  174.         case eBarHidden:
  175.             theTraitsID = mHiddenTraitsID;
  176.             break;
  177.         default:
  178.             theTraitsID = mBoundedTraitsID;
  179.             break;
  180.     }
  181.  
  182.     Int16 just = UTextTraits::SetPortTextTraits(theTraitsID);
  183.  
  184.     if (GetValue() == eBarHidden)
  185.     {
  186.         RGBColor theTextColor;
  187.         ::GetForeColor(&theTextColor);
  188.         
  189.         if (mEraseColor != eNoColorSet)
  190.             ::PmBackColor(mEraseColor);
  191.         else
  192.             ApplyForeAndBackColors();
  193.  
  194.         ::EraseRect(&theFrame);
  195.         ::RGBForeColor(&theTextColor);
  196.     }
  197.     else
  198.     {
  199.         CProgressBar::DrawSelf();
  200.     }
  201.     theFrame.right -= 3;
  202.     theFrame.left += 3;
  203.     theFrame.top -= 1;
  204.     UGraphicGizmos::PlaceStringInRect(mText, theFrame, just);
  205. }
  206.  
  207.