home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-09-24 | 3.3 KB | 139 lines | [TEXT/CWIE] |
- #ifdef PowerPlant_PCH
- #include PowerPlant_PCH
- #endif
-
-
- #include "LButtonKeyAtt.h"
-
-
- LButtonKeyAtt *LButtonKeyAtt::CreateFrom( LStream *inStream)
- {
- return new LButtonKeyAtt( inStream);
- }
-
-
- LButtonKeyAtt::LButtonKeyAtt()
- : LAttachment( msg_KeyPress, true), fKeyHandler( NULL), fKeyChar( '\0'), fHintVis( false)
- {
- }
-
-
- LButtonKeyAtt::LButtonKeyAtt( LStream *inStream)
- : fKeyHandler( NULL), fKeyChar( '\0'), fHintVis( false)
- {
- }
-
-
- LButtonKeyAtt::~LButtonKeyAtt()
- /* Remove ourselves from our keystroke-handling host. */
- {
- if ( fKeyHandler)
- fKeyHandler->RemoveAttachment( this);
- }
-
-
- void LButtonKeyAtt::SetOwnerHost( LAttachable *inOwnerHost)
- /* Locate the commander that will receive our keystrokes. */
- /* Also, determine which character should be used for pressing the button. */
- {
- LStdControl *pOwner;
- LView *pView;
- Str255 desc;
-
- LAttachment::SetOwnerHost( inOwnerHost);
- if ( pOwner = dynamic_cast<LStdControl*>( inOwnerHost)) {
- for ( pView = pOwner->GetSuperView(); pView; pView = pView->GetSuperView()) {
- if ( fKeyHandler = dynamic_cast<LCommander*>( pView))
- break;
- }
-
- if ( fKeyHandler) {
- fKeyHandler->AddAttachment( this, NULL, false);
- this->StartRepeating(); // start looking for cmd-key down
- }
-
- pOwner->GetDescriptor( desc);
- LowerText( (char*) &desc[ 1], desc[ 0]);
- fKeyChar = desc[ 1]; // should use CharByte() ?
-
- } else if ( inOwnerHost == NULL) { // we're being removed
- if ( fKeyHandler) {
- this->StopRepeating(); // stop looking for cmd-key down
- fKeyHandler->RemoveAttachment( this);
- fKeyHandler = NULL;
- }
- }
- }
-
-
- void LButtonKeyAtt::SpendTime( const EventRecord &inMacEvent)
- // If the command key is down, display the hint. If it's not, erase it.
- {
- LStdControl *pOwner;
- Boolean cmdDown;
-
- if ( ( pOwner = dynamic_cast<LStdControl*>( mOwnerHost)) && pOwner->IsEnabled()) {
- if ( ( cmdDown = ( inMacEvent.modifiers & cmdKey) != 0) &&
- !fHintVis)
- {
- this->SetHint( true);
- } else if ( !cmdDown && fHintVis) {
- this->SetHint( false);
- }
- }
- }
-
-
- void LButtonKeyAtt::ExecuteSelf( MessageT inMessage, void *ioParam)
- // Intercept fKeyHandler's keystroke events.
- {
- EventRecord *pKeyEvt = (EventRecord*) ioParam;
- LStdControl *pOwner;
-
- mExecuteHost = true;
- if ( ( pKeyEvt->modifiers & cmdKey) && fKeyChar == ( pKeyEvt->message & 0xFF)) {
- if ( ( pOwner = dynamic_cast<LStdControl*>( mOwnerHost)) && pOwner->IsEnabled()) {
- pOwner->SimulateHotSpotClick( kControlButtonPart);
- mExecuteHost = false;
- }
- }
- }
-
-
- void LButtonKeyAtt::GetHintPos( const Rect& localPaneR, Point *pPos)
- // Determine where to put hint relative to button. Hard-coded; should be improved at some point.
- {
- pPos->h = localPaneR.left - 24;
- pPos->v = localPaneR.bottom - 6;
- }
-
-
- void LButtonKeyAtt::SetHint( Boolean visible)
- // Either display the hint next to the button, or hide it.
- {
- LStdControl *pOwner;
- Rect btnR;
- Point pos;
- Byte str[2] = { char_Propeller, ' ' };
-
- if ( pOwner = dynamic_cast<LStdControl*>( mOwnerHost)) {
- if ( pOwner->FocusDraw() && pOwner->CalcLocalFrameRect( btnR))
- {
- TextFont( systemFont);
- TextSize( 12);
- TextFace( 0);
- TextMode( visible ? srcCopy : srcBic);
- this->GetHintPos( btnR, &pos);
- MoveTo( pos.h, pos.v);
- str[ 1] = fKeyChar;
- UpperText( (char*) &str[ 1], 1);
- DrawText( str, 0, sizeof str);
- TextMode( srcCopy);
- }
- }
- fHintVis = visible;
- }
-
-
-
-