home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CClusterView.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.6 KB  |  169 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 <LStream.h>
  24. #include <UTextTraits.h>
  25. #include <UDrawingState.h>
  26. #include <UDrawingUtils.h>
  27.  
  28. #include "CClusterView.h"
  29. #include "UStdBevels.h"
  30.  
  31. // some private constants
  32. const Int16 kClusterIndentSize = 13;
  33. const Int16 kClusterTitleFudgeSize = 4;
  34.  
  35. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  36. //    Ñ    
  37. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  38.  
  39. CClusterView::CClusterView(LStream *inStream)
  40.     :    LView(inStream)
  41. {
  42.     inStream->ReadPString(mTitle);
  43.     inStream->ReadData(&mTraitsID, sizeof(ResIDT));
  44. }
  45.  
  46. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  47. //    Ñ    
  48. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  49.  
  50. CClusterView::~CClusterView()
  51. {
  52. }
  53.  
  54. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  55. //    Ñ    
  56. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  57.  
  58. void CClusterView::FinishCreateSelf(void)
  59. {
  60.     LView::FinishCreateSelf();
  61.  
  62.     CalcTitleFrame();    
  63. }
  64.  
  65. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  66. //    Ñ    
  67. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  68.  
  69. StringPtr CClusterView::GetDescriptor(Str255 outDescriptor) const
  70. {
  71.     return LString::CopyPStr(mTitle, outDescriptor);
  72. }
  73.  
  74. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  75. //    Ñ    
  76. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  77.  
  78. void CClusterView::SetDescriptor(ConstStr255Param inDescriptor)
  79. {
  80.     mTitle = inDescriptor;
  81.     CalcTitleFrame();
  82. }
  83.  
  84. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  85. //    Ñ    
  86. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  87.  
  88. void CClusterView::DrawSelf(void)
  89. {
  90.     StColorPenState theStateSaver;
  91.     theStateSaver.Normalize();
  92.     
  93.     Rect theFrame;
  94.     CalcLocalFrameRect(theFrame);
  95.  
  96.     Rect theOutlineFrame = theFrame;
  97.     theOutlineFrame.top += (mTitleFrame.bottom - mTitleFrame.top) / 2;
  98.  
  99.     UTextTraits::SetPortTextTraits(mTraitsID);
  100.  
  101.     Int16 theDepth;
  102.     StDeviceLoop theLoop(theFrame);
  103.     while (theLoop.NextDepth(theDepth))
  104.         {
  105.         if (theDepth > 4)
  106.             {
  107.             // Draw the frame in color
  108.             ::PmForeColor(eStdGray40);
  109.             ::PmBackColor(eStdGray53);
  110.             }
  111.  
  112.         ::PenPat(&qd.gray);            
  113.         ::FrameRect(&theOutlineFrame);
  114.         
  115.         if (mTitle.Length() > 0)
  116.             {
  117.             StColorState::Normalize();
  118.             ApplyForeAndBackColors();
  119.             ::EraseRect(&mTitleFrame);
  120.             ::MoveTo(mTitleFrame.left + kClusterTitleFudgeSize, mTitleBaseline);
  121.             ::DrawText(mTitle, 1, mTitle.Length());
  122.             }
  123.         }
  124. }
  125.  
  126. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  127. //    Ñ    
  128. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  129.  
  130. void CClusterView::CalcTitleFrame(void)
  131. {
  132.     if (mTitle.Length() == 0)
  133.         return;
  134.         
  135.     Rect theFrame;
  136.     CalcLocalFrameRect(theFrame);
  137.     mTitleFrame = theFrame;
  138.  
  139.     Int16 theJust = UTextTraits::SetPortTextTraits(mTraitsID);
  140.     Int16 theTextWidth = ::StringWidth(mTitle) + (2 * kClusterTitleFudgeSize);
  141.     
  142.     FontInfo theInfo;
  143.     ::GetFontInfo(&theInfo);
  144.     Int16 theTextHeight = theInfo.ascent + theInfo.descent + theInfo.leading;
  145.     
  146.     mTitleBaseline = theFrame.top + theInfo.ascent;
  147.     mTitleFrame.bottom = mTitleFrame.top + theTextHeight;
  148.     
  149.     switch (theJust)
  150.         {
  151.         case teCenter:
  152.             mTitleFrame.left += ((theFrame.right - theFrame.left - theTextWidth) / 2);
  153.             mTitleFrame.right = mTitleFrame.left + theTextWidth;
  154.             break;
  155.                 
  156.         case teFlushRight:
  157.             mTitleFrame.right = theFrame.right - kClusterIndentSize;
  158.             mTitleFrame.left = mTitleFrame.right - theTextWidth;
  159.             break;
  160.  
  161.         case teFlushDefault:
  162.         case teFlushLeft:
  163.         default:
  164.             mTitleFrame.left += kClusterIndentSize;
  165.             mTitleFrame.right = mTitleFrame.left + theTextWidth;
  166.             break;
  167.         }
  168. }
  169.