home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CCaption.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  3.9 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. // CCaption.cp
  21.  
  22. #include "CCaption.h"
  23. #include <LStream.h>
  24. #include "PascalString.h"
  25. #include <TextUtils.h>
  26. #include <UGraphicsUtilities.h>
  27.  
  28. ///////////////////////////////////////////////////////////////////
  29. // constants
  30. const short booleanStringResID = 901;    // resource ID of the boolean strings in macfe.r
  31.  
  32. ///////////////////////////////////////////////////////////////////
  33. // CCaption
  34.  
  35. void CCaption::DrawSelf()
  36. {
  37.     Rect    frame;
  38.     CalcLocalFrameRect(frame);
  39.     
  40.     StColorPenState    theColorPenState;
  41.     StColorPenState::Normalize ();
  42.     StTextState        theTextState;
  43.  
  44.     Int16    just = UTextTraits::SetPortTextTraits(mTxtrID);
  45.     
  46.     // Ñ Save off the text color as setup by the TextTrait
  47.     RGBColor    textColor;
  48.     ::GetForeColor(&textColor);
  49.     ApplyForeAndBackColors();
  50.     ::RGBForeColor(&textColor);
  51.     
  52.     // the following code adapted from LGARadioButton.cp
  53.     
  54.     // Ñ Loop over any devices we might be spanning and handle the drawing
  55.     // appropriately for each devices screen depth
  56.     StDeviceLoop    theLoop ( frame );
  57.     Int16            depth;
  58.     while ( theLoop.NextDepth ( depth )) 
  59.     {
  60.         if ( depth < 4 )        //    Ñ BLACK & WHITE
  61.         {
  62.             if ( !IsEnabled() )
  63.             {
  64.                 // Ñ If the caption is dimmed then we use the grayishTextOr 
  65.                 // transfer mode to draw the text
  66.                 ::TextMode ( grayishTextOr );
  67.             }
  68.         }
  69.         else if ( depth >= 4 )     // Ñ COLOR
  70.         {
  71.             if ( !IsEnabled() )
  72.             {
  73.                 // Ñ If the control is dimmed then we have to do our own version of the
  74.                 // grayishTextOr as it does not appear to work correctly across
  75.                 // multiple devices
  76.                 RGBColor textColor2 = UGraphicsUtilities::Lighten( &textColor );
  77.                 ::TextMode ( srcOr );
  78.                 ::RGBForeColor ( &textColor2 );
  79.             }
  80.         }    
  81.  
  82.         UTextDrawing::DrawWithJustification((Ptr)&mText[1], mText[0], frame, just);
  83.     }
  84. }
  85.  
  86. void CCaption::EnableSelf()
  87. {
  88.     Draw( nil );
  89. }
  90.  
  91. void CCaption::DisableSelf()
  92. {
  93.     Draw( nil );
  94. }
  95.  
  96. ///////////////////////////////////////////////////////////////////
  97. // CListenerCaption
  98.  
  99. // Default constructor
  100. CListenerCaption::CListenerCaption( LStream *inStream ) : labelNum( default_menu_item ),
  101.     CCaption ( inStream )
  102. {
  103. }
  104.  
  105. // Default destructor
  106. CListenerCaption::~CListenerCaption()
  107. {
  108. }
  109.  
  110. // Change label
  111. void
  112. CListenerCaption::ChangeText( const LabelNum& newLabelNum )
  113. {
  114.     Str255    string;
  115.     ::GetIndString( string, resourceID, newLabelNum );
  116.     // needs check and exception         
  117.     SetDescriptor( string );
  118.     labelNum = newLabelNum;
  119. }
  120.  
  121. // Return the label num
  122. LabelNum
  123. CListenerCaption::GetLabelNum() const
  124. {
  125.     return labelNum;
  126. }
  127.  
  128. // Return the label num
  129. void
  130. CListenerCaption::SetLabelNum( const LabelNum& newLabelNum ) 
  131. {
  132.     labelNum = newLabelNum;
  133. }
  134.  
  135. // Override of the ListenToMessage method
  136. //
  137. // *** Needs exceptions
  138. //
  139. void    
  140. CListenerCaption::ListenToMessage( MessageT  inMessage, void *ioParam)
  141. {
  142.     if( mMsg_changeText == inMessage )
  143.     {
  144.             LabelNum menuItem = *( static_cast< LabelNum* >( ioParam ) );
  145.             ChangeText( menuItem );        
  146.     }
  147. }
  148.  
  149. // Needs to be called before using this class
  150. // 
  151. // *** Needs exceptions
  152. //
  153. void
  154. CListenerCaption::Init( const short strResID, const MessageT& getNew_msg )
  155. {
  156.     if( getNew_msg )
  157.          mMsg_changeText = getNew_msg;
  158.              
  159.     if( strResID )
  160.         resourceID = strResID;
  161. }
  162.