home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CProxyCaption.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.5 KB  |  154 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. //    CProxyCaption.cp
  21. //
  22. // ===========================================================================
  23.  
  24. #include "CProxyCaption.h"
  25.  
  26. #include "mfinder.h" // needed for workaround function to bug in Appe's
  27.                      // ::TruncText and ::TruncString - andrewb 6/20/97
  28.                      
  29. #include <UGAColorRamp.h>
  30. #include <UDrawingUtils.h>
  31. #include <UNewTextDrawing.h>
  32.  
  33. // ---------------------------------------------------------------------------
  34. //        Ñ CProxyPane
  35. // ---------------------------------------------------------------------------
  36.  
  37. CProxyCaption::CProxyCaption(
  38.     LStream*        inStream)
  39.     
  40.     :    super(inStream)
  41. {
  42. }
  43.  
  44. // ---------------------------------------------------------------------------
  45. //        Ñ FinishCreateSelf
  46. // ---------------------------------------------------------------------------
  47.     
  48. void
  49. CProxyCaption::FinishCreateSelf()
  50. {
  51.     super::FinishCreateSelf();
  52.     
  53.     CalcLocalFrameRect(mOriginalFrame);
  54. }
  55.  
  56. // ---------------------------------------------------------------------------
  57. //        Ñ SetDescriptor
  58. // ---------------------------------------------------------------------------
  59.     
  60. void
  61. CProxyCaption::SetDescriptor(
  62.     ConstStringPtr    inDescriptor)
  63. {
  64.     super::SetDescriptor(inDescriptor);
  65.     
  66.     FocusDraw();
  67.     
  68.     // Adjust frame to fit new descriptor
  69.     
  70.     Rect    frame = mOriginalFrame;
  71.     Rect    newFrame;
  72.     
  73.     Int16    just = UTextTraits::SetPortTextTraits(mTxtrID);
  74.  
  75.     StringPtr theDescriptor = const_cast<StringPtr>(inDescriptor);
  76.     
  77.     frame.left += 1; // A little extra padding looks better
  78.  
  79.     UNewTextDrawing::MeasureWithJustification(
  80.                                     reinterpret_cast<char*>(&theDescriptor[1]),
  81.                                     inDescriptor[0],
  82.                                     frame,
  83.                                     just,
  84.                                     newFrame,
  85.                                     true);
  86.                             
  87.     if ((newFrame.right - newFrame.left) > (frame.right - frame.left))
  88.     {
  89.         newFrame = frame;
  90.     }
  91.     
  92.     
  93.          // The + 2 factor seems to be necessary to not lose the
  94.          // last word of the title
  95.     ResizeFrameTo((newFrame.right - newFrame.left) + 2, newFrame.bottom - newFrame.top, true);
  96. }    
  97.  
  98. // ---------------------------------------------------------------------------
  99. //        Ñ DrawSelf
  100. // ---------------------------------------------------------------------------
  101.  
  102. void
  103. CProxyCaption::DrawSelf()
  104. {
  105.     Rect    frame;
  106.     CalcLocalFrameRect(frame);
  107.     
  108.     Int16    justification = UTextTraits::SetPortTextTraits(mTxtrID);
  109.  
  110.     ::RGBBackColor(&UGAColorRamp::GetBlackColor());
  111.     ::RGBForeColor(&UGAColorRamp::GetWhiteColor());
  112.     
  113.     ::EraseRect(&frame);
  114.     
  115.     frame.left += 1; // A little extra padding looks better
  116.     
  117.     DrawText((Ptr)&mText[1], mText[0], frame);
  118. }
  119.  
  120. // ---------------------------------------------------------------------------
  121. //        Ñ DrawText
  122. // ---------------------------------------------------------------------------
  123. //    NOTE: This version is differs from UDrawingUtils::DrawWithJustification
  124. //    in that we don't wrap lines, we just draw one line truncated. However,
  125. //    the measurements are identical to UDrawingUtils::DrawWithJustification
  126. //    so that UNewTextDrawing::MeasureWithJustification will correspond to what
  127. //    is drawn.
  128.  
  129. void
  130. CProxyCaption::DrawText(
  131.     Ptr                inText,
  132.     Int32            inLength,
  133.     const Rect&        inRect)
  134. {
  135.     FontInfo fontInfo;
  136.     
  137.     ::GetFontInfo(&fontInfo);
  138.     
  139.     Int16 lineBase = inRect.top + fontInfo.ascent + fontInfo.leading;
  140.     
  141.     StClipRgnState saveClip;                // Draw within input rectangle
  142.     saveClip.ClipToIntersection(inRect);
  143.     
  144.     ::MoveTo(inRect.left, lineBase);
  145.     
  146.     short length = inLength;
  147.     
  148.     // DANGER! If you were to use Apple's ::TruncText with TruncMiddle as the
  149.     // last parameter you run the risk of crashing--in a very bad way. andrewb
  150.     MiddleTruncationThatWorks((char *)inText, length, inRect.right - inRect.left);
  151.     ::DrawText(inText, 0, length);
  152. }
  153.  
  154.