home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / COffscreenCaption.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.5 KB  |  162 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. //    TBD:
  21. //        -    If this caption is going to resize, we need code to recalc the
  22. //            offscreen world accordingly.
  23. //
  24. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  25.  
  26. #ifdef PowerPlant_PCH
  27. #include PowerPlant_PCH
  28. #endif
  29.  
  30. #include <PP_Messages.h>
  31. #include <UDrawingState.h>
  32. #include <UDrawingUtils.h>
  33. #include <UGWorld.h>
  34. #include <UMemoryMgr.h>
  35. #include <UTextTraits.h>
  36.  
  37. #include "COffscreenCaption.h"
  38.  
  39. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  40. //    Ñ    
  41. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  42.  
  43. COffscreenCaption::COffscreenCaption(LStream* inStream)
  44.     :    LCaption(inStream)
  45. {
  46.     // The erase color is initialized to -1 because it is an invalid palette
  47.     // index.
  48.     mEraseColor = -1;
  49. }
  50.  
  51. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  52. //    Ñ    
  53. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  54.  
  55. COffscreenCaption::COffscreenCaption(
  56.     const SPaneInfo&    inPaneInfo,
  57.     ConstStringPtr        inString,
  58.     ResIDT                inTextTraitsID)
  59.         :    LCaption(inPaneInfo, inString, inTextTraitsID)
  60. {
  61.     // The erase color is initialized to -1 because it is an invalid palette
  62.     // index.
  63.     mEraseColor = -1;
  64. }
  65.  
  66. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  67. //    Ñ    
  68. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  69.  
  70. void COffscreenCaption::SetDescriptor(ConstStringPtr inDescriptor)
  71. {
  72.     if (inDescriptor == NULL)
  73.         mText = "\p";
  74.     else
  75.         mText = inDescriptor;
  76.         
  77.     Draw(NULL);
  78. }
  79.  
  80. void COffscreenCaption::SetDescriptor(const char* inCDescriptor)
  81. {
  82.     if (inCDescriptor == NULL)
  83.         mText = "\p";
  84.     else
  85.         mText = inCDescriptor;
  86.         
  87.     Draw(NULL);
  88. }
  89.  
  90. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  91. //    Ñ    
  92. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  93.  
  94. void COffscreenCaption::Draw(RgnHandle inSuperDrawRgnH)
  95. {
  96.     Rect theFrame;
  97.     if ((mVisible == triState_On) && CalcPortFrameRect(theFrame) &&
  98.             ((inSuperDrawRgnH == nil) || RectInRgn(&theFrame, inSuperDrawRgnH)) && FocusDraw())
  99.         {
  100.         PortToLocalPoint(topLeft(theFrame));    // Get Frame in Local coords
  101.         PortToLocalPoint(botRight(theFrame));
  102.  
  103.         if (ExecuteAttachments(msg_DrawOrPrint, &theFrame))
  104.             {
  105.             Boolean bDidDraw = false;
  106.  
  107.             StColorPenState thePenSaver;
  108.             StColorPenState::Normalize();
  109.             
  110.             // Fail safe offscreen drawing
  111.             StValueChanger<EDebugAction> okayToFail(gDebugThrow, debugAction_Nothing);
  112.             try
  113.                 {            
  114.                 LGWorld theOffWorld(theFrame, 0, useTempMem);
  115.  
  116.                 if (!theOffWorld.BeginDrawing())
  117.                     throw memFullErr;
  118.                     
  119.                 DrawSelf();
  120.                     
  121.                 theOffWorld.EndDrawing();
  122.                 theOffWorld.CopyImage(GetMacPort(), theFrame, srcCopy);
  123.                 bDidDraw = true;
  124.                 }
  125.             catch (...)
  126.                 {
  127.                 //     & draw onscreen
  128.                 }
  129.                 
  130.             if (!bDidDraw)
  131.                 DrawSelf();
  132.             }
  133.         }
  134. }
  135.  
  136. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  137. //    Ñ    DrawSelf
  138. //
  139. //    If the erase color has been set, we'll erase the background in that
  140. //    color.  Otherwise we should use the window's colors.    
  141. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  142.  
  143. void COffscreenCaption::DrawSelf(void)
  144. {
  145.     Rect    theFrame;
  146.     CalcLocalFrameRect(theFrame);
  147.     
  148.     Int16    just = UTextTraits::SetPortTextTraits(mTxtrID);
  149.     
  150.     RGBColor theTextColor;
  151.     ::GetForeColor(&theTextColor);
  152.     
  153.     if (mEraseColor != -1)
  154.         ::PmBackColor(mEraseColor);
  155.     else
  156.         ApplyForeAndBackColors();
  157.  
  158.     ::EraseRect(&theFrame);
  159.     ::RGBForeColor(&theTextColor);
  160.     UTextDrawing::DrawWithJustification((Ptr)&mText[1], mText[0], theFrame, just);
  161. }    
  162.