home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-01 | 8.8 KB | 375 lines | [TEXT/CWIE] |
- /*
- File: CDimmerCluster.cp
-
- Contains: Implementation of the dimmer cluster and dimming edittext classes.
-
- Written by: Sak Wathanasin
- Network Analysis Ltd
- 178 Wainbody Ave South
- Coventry CV3 6BX
- UK
- Phone: (+44) 1203 419996
- E-mail: sw@network-analysis-ltd.co.uk
-
- Thanks to: Donald E. Carlile who contributed the dimmable caption
- (carlile@beachnet.gen.ca.us)
-
- Copyright: © 1995 Network Analysis Ltd. All rights reserved.
-
- Change History (most recent first):
-
- <1.1> 01/12/95 dec Add dimmable captions
- <1.0> 07/08/95 sw First public release.
-
- To Do:
- */
-
- #ifndef __CDimmerCluster__
- #include "CDimmerCluster.h"
- #endif
-
- // This implements a (transparent) view that dims its sub-panes
- // depending on the setting of a distinguished sub-pane (the "master").
- // This is often a checkbox, but any LControl sub-class can be used.
- //
- // The idea is to use Constructor for most of the hard-work: the pane ID
- // of the master is put into the "user constant" field of the view,
- // and each sub-pane that is to be dimmed has its user constant set to 1.
-
- CDimmerCluster::CDimmerCluster()
- {
- mController = nil;
- }
-
- CDimmerCluster::CDimmerCluster(LStream* inStream)
- : LView(inStream)
- {
- mController = nil;
- }
-
- CDimmerCluster::CDimmerCluster(const SPaneInfo &inPaneInfo,
- const SViewInfo &inViewInfo)
- : LView(inPaneInfo, inViewInfo)
- {
- mController = nil;
- }
-
- CDimmerCluster::CDimmerCluster(const LView &inOriginal)
- : LView(inOriginal)
- {
- mController = this->FindController();
- }
-
-
- CDimmerCluster::~CDimmerCluster()
- {
- }
-
- #pragma segment CDim
- CDimmerCluster*
- CDimmerCluster::CreateDimmerStream(LStream *inStream) //Override
- {
- return (new CDimmerCluster(inStream));
- }
-
-
- #pragma segment CDim
- void CDimmerCluster::FinishCreate() //Override
-
- {
- LView::FinishCreate (); // do the std thing
- // now add ourselves as a listener for the controller
- mController = this->FindController();
- mController->AddListener(this);
- }
-
-
- // The controller sub-pane must broadcast a message "cmd_DimGroup" (3000)
- // whose ioParm is 0 or 1 depending on whether the control is on or
- // off (0 = dim, 1 = don't dim)
- #pragma segment CDim
- void CDimmerCluster::ListenToMessage(MessageT inMessage, void *ioParam)
- {
- if (inMessage == cmd_DimGroup)
- {
-
- SignalIf_(mController == nil);
-
- // if it is the master controller, then dim/undim the other controls as appr
- LListIterator iterator(mSubPanes, iterate_FromStart);
- LPane *theSub;
- if (*(long*)ioParam == 0)
- {
- // dim: for all sub-panes we disable if the user flag is set
- while (iterator.Next(&theSub))
- {
- if (theSub->GetUserCon() == eOn && theSub->IsEnabled())
- {
- theSub->SetUserCon(eWasDimmed);
- theSub->Disable();
- }
- }
- }
- else
- {
- // undim any controls that were dimmed by us
- while (iterator.Next(&theSub))
- {
- if (theSub->GetUserCon() == eWasDimmed)
- {
- theSub->SetUserCon(eOn);
- theSub->Enable();
- }
- }
- }
- }
- }
-
- #pragma segment CDim
- LControl* CDimmerCluster::FindController()
- {
- return (LControl*) FindPaneByID(this->GetUserCon());
-
- }
-
- // ---------------------------------------------------------------------------
- // • CreateEditFieldStream
- // ---------------------------------------------------------------------------
- // Create a new EditField object from the data in a Stream
-
- CDimmableEditText*
- CDimmableEditText::CreateDimmableEditTextStream(
- LStream *inStream)
- {
- return (new CDimmableEditText(inStream));
- }
-
-
- // ---------------------------------------------------------------------------
- // • CDimmableEditText
- // ---------------------------------------------------------------------------
- // Default Contructor
-
- CDimmableEditText::CDimmableEditText()
- :LEditField()
- {
- mWasTarget = false;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CDimmableEditText(CDimmableEditText&)
- // ---------------------------------------------------------------------------
- // Copy Contructor
-
- CDimmableEditText::CDimmableEditText(
- const CDimmableEditText &inOriginal)
- : LEditField(inOriginal)
- {
- mWasTarget = false;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CDimmableEditText
- // ---------------------------------------------------------------------------
- // Contruct from input parameters
-
- CDimmableEditText::CDimmableEditText(
- const SPaneInfo &inPaneInfo,
- Str255 inString,
- ResIDT inTextTraitsID,
- Int16 inMaxChars,
- Boolean inHasBox,
- Boolean inHasWordWrap,
- KeyFilterFunc inKeyFilter,
- LCommander *inSuper)
- : LEditField(inPaneInfo, inString, inTextTraitsID, inMaxChars, inHasBox, inHasWordWrap, inKeyFilter, inSuper)
- {
- mWasTarget = false;
- }
-
-
- CDimmableEditText::CDimmableEditText(
- const SPaneInfo &inPaneInfo,
- Str255 inString,
- ResIDT inTextTraitsID,
- Int16 inMaxChars,
- Uint8 inAttributes,
- KeyFilterFunc inKeyFilter,
- LCommander *inSuper)
- : LEditField(inPaneInfo, inString, inTextTraitsID, inMaxChars, inAttributes, inKeyFilter, inSuper)
- {
- mWasTarget = false;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CDimmableEditText(LStream*)
- // ---------------------------------------------------------------------------
- // Contruct an EditField from the data in a Stream
-
- CDimmableEditText::CDimmableEditText(
- LStream *inStream)
- : LEditField(inStream)
- {
- mWasTarget = false;
- }
-
- void
- CDimmableEditText::DisableSelf()
- {
- TEHandle aTEH = GetMacTEH();
-
- // checking for systems without grayishTextOr
- // left as an exercise for the reader, but I don't
- // think PP runs on systems that don't have grayishTextOr...
- (*aTEH)->txMode = grayishTextOr;
- mWasTarget = this->IsTarget();
- if (mWasTarget)
- {
- this->SwitchTarget(nil);
- }
- this->Disable();
- this->Refresh(); // do the std thing
- }
-
- void
- CDimmableEditText::EnableSelf()
- {
- TEHandle aTEH = GetMacTEH();
-
- (*aTEH)->txMode = mTxMode;
- this->Enable();
- if (this->WasTarget())
- {
- this->SwitchTarget(this);
- }
- this->Refresh(); // do the std thing
- }
-
- void
- CDimmableEditText::FinishCreate() //Override
- {
- TEHandle aTEH = GetMacTEH();
- mTxMode = (*aTEH)->txMode;
- }
-
- //CDimCaption.cp
- //Donald E. Carlile 1995
- //I hestitate to copyright, because a lot of this is Powerplant modified slightly
-
- // ---------------------------------------------------------------------------
- // Ä CreateCaptionStream
- // ---------------------------------------------------------------------------
- // Create a new Caption object from the data in a Stream
-
- CDimCaption*
- CDimCaption::CreateDimCaptionStream(
- LStream *inStream)
- {
- return (new CDimCaption(inStream));
- }
-
-
- // ---------------------------------------------------------------------------
- // Ä CDimCaption
- // ---------------------------------------------------------------------------
- // Default Constructor
-
- CDimCaption::CDimCaption()
- :LCaption()
- {
- Int32 myIntensity = 34952;
- mDimColor.red = mDimColor.green = mDimColor.blue = myIntensity;
- }
-
-
- // ---------------------------------------------------------------------------
- // Ä CDimCaption(const LCaption&)
- // ---------------------------------------------------------------------------
- // Copy Constructor
-
- CDimCaption::CDimCaption(
- const CDimCaption &inOriginal)
- : LCaption(inOriginal)
- {
- mText = inOriginal.mText;
- mTxtrID = inOriginal.mTxtrID;
- Int32 myIntensity = 34952;
- mDimColor.red = mDimColor.green = mDimColor.blue = myIntensity;
- }
-
-
- // ---------------------------------------------------------------------------
- // Ä CDimCaption(SPaneInfo&, Str255, ResIDT)
- // ---------------------------------------------------------------------------
- // Construct from parameters. Use this constructor to create a Caption
- // from runtime data.
-
- CDimCaption::CDimCaption(
- const SPaneInfo &inPaneInfo,
- ConstStringPtr inString,
- ResIDT inTextTraitsID)
- : LCaption(inPaneInfo, inString,inTextTraitsID)
- {
- Int32 myIntensity = 34952;
- mDimColor.red = mDimColor.green = mDimColor.blue = myIntensity;
- }
-
-
- // ---------------------------------------------------------------------------
- // Ä CDimCaption(LStream*)
- // ---------------------------------------------------------------------------
- // Construct from data in a Stream
-
- CDimCaption::CDimCaption(
- LStream *inStream)
- : LCaption(inStream)
- {
- Int32 myIntensity = 34952;
- mDimColor.red = mDimColor.green = mDimColor.blue = myIntensity;
- }
-
-
- // ---------------------------------------------------------------------------
- // Ä ~CDimCaption
- // ---------------------------------------------------------------------------
- // Destructor
-
- CDimCaption::~CDimCaption()
- {
- }
-
- void
- CDimCaption::EnableSelf()
- {
- DrawSelf();
- }
-
- void
- CDimCaption::DisableSelf()
- {
- DrawSelf();
- }
-
-
- void
- CDimCaption::DrawSelf()
- {
- Rect frame;
- CalcLocalFrameRect(frame);
-
- Int16 just = UTextTraits::SetPortTextTraits(mTxtrID);
-
- RGBColor textColor;
- if (GetUserCon() == eWasDimmed) {
- textColor = mDimColor;
- } else {
- ::GetForeColor(&textColor);
- }
- ApplyForeAndBackColors();
- ::RGBForeColor(&textColor);
-
- UTextDrawing::DrawWithJustification((Ptr)&mText[1], mText[0], frame, just);
- }