1998-08-05 06:50:38 +04:00
|
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-08-05 06:50:38 +04:00
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
|
* rights and limitations under the License.
|
1998-08-05 06:50:38 +04:00
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
|
*
|
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-08-05 06:50:38 +04:00
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
|
* Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s):
|
1998-08-05 06:50:38 +04:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "CColorCaption.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CChameleonCaption :: CChameleonCaption ( LStream* inStream )
|
|
|
|
|
: LGACaption(inStream)
|
|
|
|
|
{
|
|
|
|
|
mTextColor.red = mTextColor.green = mTextColor.blue = 0; // black
|
|
|
|
|
mBackColor.red = mBackColor.green = mBackColor.blue = 0xFFFF; // white
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// SetColor
|
|
|
|
|
//
|
|
|
|
|
// Use given colors instead. First version sets both fg and bg, second version only
|
|
|
|
|
// sets the fg color.
|
|
|
|
|
//
|
|
|
|
|
void
|
|
|
|
|
CChameleonCaption :: SetColor ( RGBColor & inTextColor, RGBColor & inBackColor )
|
|
|
|
|
{
|
|
|
|
|
mTextColor = inTextColor;
|
|
|
|
|
mBackColor = inBackColor;
|
|
|
|
|
|
|
|
|
|
} // SetColor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
CChameleonCaption :: SetColor ( RGBColor & inTextColor )
|
|
|
|
|
{
|
|
|
|
|
mTextColor = inTextColor;
|
|
|
|
|
|
|
|
|
|
} // SetColor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// DrawSelf
|
|
|
|
|
//
|
|
|
|
|
// Taken from LGACaption and modified to use our colors instead of those in
|
|
|
|
|
// the text traits rsrc. Differences from the original are marked.
|
|
|
|
|
//
|
|
|
|
|
void
|
|
|
|
|
CChameleonCaption :: DrawSelf()
|
|
|
|
|
{
|
|
|
|
|
Rect localFrame;
|
|
|
|
|
CalcLocalFrameRect ( localFrame );
|
|
|
|
|
|
|
|
|
|
// <20> Setup the text traits and get the justification
|
|
|
|
|
Int16 just = UTextTraits::SetPortTextTraits ( mTxtrID );
|
|
|
|
|
|
|
|
|
|
// <20> Get the fore and back colors applied
|
|
|
|
|
ApplyForeAndBackColors ();
|
|
|
|
|
RGBColor textColor = mTextColor;
|
|
|
|
|
|
|
|
|
|
// NSCP -- Apply our own text colors, not those of the text traits rsrc
|
|
|
|
|
::RGBBackColor(&mBackColor);
|
|
|
|
|
|
|
|
|
|
// <20> Setup a device loop so that we can handle drawing at the correct bit depth
|
|
|
|
|
StDeviceLoop theLoop ( localFrame );
|
|
|
|
|
Int16 depth;
|
|
|
|
|
while ( theLoop.NextDepth ( depth ))
|
|
|
|
|
{
|
|
|
|
|
// <20> If we are drawing to a color screen then we are going to lighten
|
|
|
|
|
// the color of the text when we are disabled
|
|
|
|
|
if ( depth > 4 && !IsActive ())
|
|
|
|
|
textColor = UGraphicsUtilities::Lighten ( &textColor );
|
|
|
|
|
|
|
|
|
|
// NSCP -- Set the foreground color to our own color
|
|
|
|
|
::RGBForeColor ( &textColor );
|
|
|
|
|
|
|
|
|
|
// <20> Now we can finally get the text drawn
|
1998-10-21 18:32:48 +04:00
|
|
|
|
this->DrawText(localFrame, just);
|
1998-08-05 06:50:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // DrawSelf
|
1998-10-21 18:32:48 +04:00
|
|
|
|
void
|
|
|
|
|
CChameleonCaption :: DrawText(Rect frame, Int16 inJust)
|
|
|
|
|
{
|
|
|
|
|
UTextDrawing::DrawWithJustification ( (Ptr)&mText[1], mText[0], frame, inJust );
|
|
|
|
|
|
|
|
|
|
}
|
1998-08-05 06:50:38 +04:00
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
CChameleonBroadcastCaption :: CChameleonBroadcastCaption ( LStream* inStream )
|
|
|
|
|
: CChameleonCaption(inStream)
|
|
|
|
|
{
|
|
|
|
|
*inStream >> mMessage;
|
|
|
|
|
*inStream >> mRolloverTraits;
|
|
|
|
|
|
|
|
|
|
mSavedTraits = GetTextTraitsID(); // cache original text traits
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// ClickSelf
|
|
|
|
|
//
|
|
|
|
|
// Broadcast our message when clicked on
|
|
|
|
|
//
|
|
|
|
|
void
|
|
|
|
|
CChameleonBroadcastCaption :: ClickSelf ( const SMouseDownEvent & inEvent )
|
|
|
|
|
{
|
1998-08-21 01:49:11 +04:00
|
|
|
|
if ( ! ::WaitMouseMoved(inEvent.macEvent.where) )
|
|
|
|
|
BroadcastMessage ( mMessage );
|
1998-08-05 06:50:38 +04:00
|
|
|
|
|
|
|
|
|
} // ClickSelf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// MouseWithin
|
|
|
|
|
//
|
|
|
|
|
// If text traits are specified that are different from the default, set them
|
|
|
|
|
// when the mouse is within this view
|
|
|
|
|
//
|
|
|
|
|
void
|
|
|
|
|
CChameleonBroadcastCaption :: MouseWithin ( Point inWhere, const EventRecord & inEvent )
|
|
|
|
|
{
|
|
|
|
|
#if 0
|
|
|
|
|
if ( GetTextTraitsID() != mRolloverTraits ) {
|
|
|
|
|
SetTextTraitsID ( mRolloverTraits );
|
|
|
|
|
Draw(NULL);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
} // MouseWithin
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// MouseLeave
|
|
|
|
|
//
|
|
|
|
|
// Restore the text traits to normal when the mouse leaves.
|
|
|
|
|
//
|
|
|
|
|
void
|
1998-09-29 21:20:12 +04:00
|
|
|
|
CChameleonBroadcastCaption :: MouseLeave ( )
|
1998-08-05 06:50:38 +04:00
|
|
|
|
{
|
|
|
|
|
#if 0
|
|
|
|
|
if ( mSavedTraits != GetTextTraitsID() ) {
|
|
|
|
|
SetTextTraitsID ( mSavedTraits );
|
|
|
|
|
Draw(NULL);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
} // MouseLeave
|