home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-30 | 4.4 KB | 248 lines | [TEXT/KAHL] |
- /***********************************************************************************
- CExpanderLabel.h
-
- Copyright © 1994 B-Ray Software. All rights reserved.
- Developed using Symantec C++ 7.0.2 and Symantec's TCL library.
- Portions of this code courtesy Symantec, Inc.
-
- This code may be freely distributed as long as this notice remains. This code
- may not be used in any commercial software without the consent of B-Ray Software.
-
- ---
-
- CExpanderLabel manages the title of a CExpander object. The label, if selectable
- can also issue a command when double-clicked.
-
- ***********************************************************************************/
- #include "CExpanderLabel.h"
- #include "CExpanderLabelEnv.h"
-
- extern short gClicks;
-
-
- TCL_DEFINE_CLASS_D1( CExpanderLabel, CExpanderText );
-
-
- /*
- * CExpanderLabel constructor
- *
- * Default constructor - should only be called when created by a file read.
- */
-
- CExpanderLabel :: CExpanderLabel() : CExpanderText()
- {
- itsText = NULL;
- itsCommand = cmdNull;
-
- SetWantsClicks( TRUE );
-
- TCL_END_CONSTRUCTOR
- }
-
-
- /*
- * CExpanderLabel constructor
- *
- * Normal constructor - should always be called when created in code.
- */
-
- CExpanderLabel :: CExpanderLabel( CView *anEnclosure, CBureaucrat *aSupervisor,
- short aWidth, short aHeight, short aHLoc, short aVLoc,
- SizingOption aHSizing, SizingOption aVSizing )
- : CExpanderText( anEnclosure, aSupervisor, aWidth, aHeight, aHLoc, aVLoc,
- aHSizing, aVSizing )
- {
- itsText = NULL;
- itsCommand = cmdNull;
-
- SetWantsClicks( TRUE );
-
- MakeEnvironment(); // create drawing environment for the label.
-
- TCL_END_CONSTRUCTOR
- }
-
-
- /*
- * CExpanderLabel destructor
- *
- * Just a place-holder for Inspector
- */
-
- CExpanderLabel :: ~CExpanderLabel()
- {
- TCL_START_DESTRUCTOR
-
- if ( itsText ) {
- ReleaseResource( itsText );
- DisposeHandle( itsText );
- }
- }
-
-
- /*
- * MakeEnvironment method
- *
- * Protected method that creates a new environment for the label to draw in.
- * Override this to install a different one.
- */
-
- void CExpanderLabel :: MakeEnvironment( void )
- {
- try_ {
- itsEnvironment = TCL_NEW( CExpanderLabelEnv, () );
- }
- catch_all_() {
- throw_same_();
- }
- end_try_;
- }
-
-
- short CExpanderLabel :: CalcFrameWidth( void )
- {
- short value = 0;
-
- if ( itsText ) {
- if ( *itsText == NULL ) {
- LoadResource( itsText );
- }
- Prepare();
- HLock( itsText );
- value = StringWidth( (unsigned char *)*itsText );
- HUnlock( itsText );
- }
-
- return value;
- }
-
-
- void CExpanderLabel :: SetLabelTextRsrcID( short rsrcID )
- {
- TCLForgetResource( itsText );
-
- itsText = GetResource( 'STR ', rsrcID );
- FailNILRes( itsText );
-
- TextSizeChanged();
- }
-
-
- void CExpanderLabel :: Draw( Rect *area )
- {
- if ( itsText == NULL || area->top >= lineHeight || area->bottom <= 0 )
- return;
-
- MoveTo( 0, ascent );
- DrawLabel( area );
-
- if ( ! printing ) {
- if ( IsSelected() ) {
- HiliteSelf( IsActive() );
- }
- }
- }
-
-
- void CExpanderLabel :: DrawLabel( Rect *area )
- {
- if ( *itsText == NULL ) {
- LoadResource( itsText );
- }
-
- HLock( itsText );
- DrawString( (unsigned char *)*itsText );
- HUnlock( itsText );
- }
-
-
- void CExpanderLabel :: Activate( void )
- {
- CExpanderText::Activate();
-
- if ( IsSelected() ) {
- Refresh();
- }
- }
-
-
- void CExpanderLabel :: Deactivate( void )
- {
- CExpanderText::Deactivate();
-
- if ( IsSelected() ) {
- Refresh();
- }
- }
-
-
- /*
- * DoClick method - OVERRIDE
- *
- * Handles clicks by the user. We are only interested in double-clicks. If
- * there is one, we issue the command we currently have stored in itsCommand.
- * Otherwise, we just let the ExpanderPane class handle the click.
- */
-
- void CExpanderLabel :: DoClick( Point hitPt, short modifierKeys, long when )
- {
- if ( gClicks == 2 ) { // double-click from user
- DoCommand( itsCommand ); // tell application to do the command
- }
- else {
- CExpanderText::DoClick( hitPt, modifierKeys, when );
- }
- }
-
-
- /*
- * PutTo method - OVERRIDE
- *
- * Writes to the stream all the info we need to save.
- */
-
- void CExpanderLabel :: PutTo( CStream &stream )
- {
- short id;
- ResType type;
- Str255 name;
-
- CExpanderText::PutTo( stream );
-
- stream << itsCommand;
-
- if ( itsText ) {
- GetResInfo( itsText, &id, &type, name );
- FailResError();
- }
- else {
- id = -1;
- }
-
- stream << id;
- }
-
-
- /*
- * GetFrom method - OVERRIDE
- *
- * Reads from the stream all of the info that we saved.
- */
-
- void CExpanderLabel :: GetFrom( CStream &stream )
- {
- short id;
-
- CExpanderText::GetFrom( stream );
-
- stream >> itsCommand;
- stream >> id;
-
- if ( id != -1 ) {
- SetLabelTextRsrcID( id );
- }
- else {
- itsText = NULL;
- }
- }
-