home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-30 | 5.6 KB | 245 lines | [TEXT/KAHL] |
- /***********************************************************************************
- CExpanderList.cp
-
- 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.
-
- ---
-
- CExpanderList expands on CExpander to provide selections. Children can be
- selected, and key events alter the active selection.
-
- ***********************************************************************************/
- #include "ExpanderMessages.h"
-
- #include "CExpanderList.h"
-
-
- TCL_DEFINE_CLASS_D1( CExpanderList, CExpander );
-
- /*
- * CExpanderList constructor
- *
- * Default constructor - should only be called when created by a file read.
- */
-
- CExpanderList :: CExpanderList() : CExpander()
- {
- selectedIndex = 0;
-
- TCL_END_CONSTRUCTOR
- }
-
-
- /*
- * CExpanderList constructor
- *
- * Normal constructor - should always be called when created in code.
- */
-
- CExpanderList :: CExpanderList( CView *anEnclosure, CBureaucrat *aSupervisor,
- short aWidth, short aHeight, short aHLoc, short aVLoc,
- SizingOption aHSizing, SizingOption aVSizing )
- : CExpander( anEnclosure, aSupervisor, aWidth, aHeight, aHLoc, aVLoc,
- aHSizing, aVSizing )
- {
- selectedIndex = 0;
-
- TCL_END_CONSTRUCTOR
- }
-
-
- /*
- * CExpanderList destructor
- *
- * Just a place-holder for Inspector
- */
-
- CExpanderList :: ~CExpanderList()
- {
- TCL_START_DESTRUCTOR
- }
-
-
- /*
- * SelectChild method
- *
- * Protected method used to select a given child. Starts the messaging
- * process going.
- */
-
- void CExpanderList :: SelectChild( CFamily *aChild )
- {
- if ( aChild ) // child is real - let it send the message
- aChild->TellParent( kExpanderChildSelect, aChild );
- else // NULL - deselect everything
- TellParent( kExpanderChildSelect, NULL );
- }
-
-
- /*
- * SetSelectedIndex method
- *
- * Public access method to select the child at the given index.
- */
-
- void CExpanderList :: SetSelectedIndex( long index )
- {
- CFamily *aChild = GetChildAtIndex( index );
-
- if ( aChild ) {
- aChild = aChild->ResolveToLeaf( FALSE ); // make sure we are at a node
- }
-
- SelectChild( aChild );
- }
-
-
- /*
- * DoKeyDown method - OVERRIDE
- *
- * Handles key down events. We are only interested in the cursor keys.
- */
-
- void CExpanderList :: DoKeyDown( char theChar, Byte keyCode, EventRecord *macEvent )
- {
- CFamily *aChild;
- Boolean childAtEnd;
-
- switch ( keyCode ) { // first - look at the keyCode value
- case KeyUpCursor: // move up a child
- aChild = PrevChild( selectedIndex );
- childAtEnd = TRUE;
- break;
-
- case KeyDownCursor: // move down a child
- aChild = NextChild( selectedIndex );
- childAtEnd = FALSE;
- break;
-
- default:
- switch ( theChar ) { // look at theChar value
- case kUpCursor: // move up a child
- aChild = PrevChild( selectedIndex );
- childAtEnd = TRUE;
- break;
-
- case kDownCursor: // move down a child
- aChild = NextChild( selectedIndex );
- childAtEnd = FALSE;
- break;
-
- default: // not handled
- CExpander::DoKeyDown( theChar, keyCode, macEvent );
- return;
- break;
- }
- }
-
- if ( aChild ) { // had a valid child to make selected
- aChild = aChild->ResolveToLeaf( childAtEnd );
- SelectChild( aChild );
- }
- else if ( itsParent ) { // let parent handle the key down event
- CPane *aPane = itsParent->ChildToPane();
- aPane->DoKeyDown( theChar, keyCode, macEvent );
- }
- }
-
-
- /*
- * SetExpandedState method - OVERRIDE
- *
- * If we had a child selected, we must deselect it if we shrink ourselves.
- */
-
- void CExpanderList :: SetExpandedState( Boolean fState )
- {
- CExpander::SetExpandedState( fState );
-
- /*
- * See if we need to adjust the selection
- */
- if ( selectedIndex > 1 && fState == FALSE ) {
- if ( itsLabel->CanSelect() == TRUE ) {
- SetSelectedIndex( 1 ); // select our header
- }
- else {
- TellParent( kExpanderChildSelect, NULL ); // don't select anything
- }
- }
- }
-
-
- /*
- * ChildMessage method - OVERRIDE
- *
- * Handles kExpanderChildSelect message. When a child wishes to become selected, we
- * remember its index as a negative value for later one when our parent broadcasts the
- * same message.
- */
-
- void CExpanderList :: ChildMessage( CFamily *aChild, long message, void *param )
- {
- if ( message == kExpanderChildSelect ) {
- selectedIndex = param ? -FindChildIndex( aChild ) : 0; // get negative index of child
- CExpander::ChildMessage( aChild, message, param ); // pass on message to parent
- selectedIndex *= -1; // make index normal
- }
- else {
- CExpander::ChildMessage( aChild, message, param ); // let superclass handle rest
- }
- }
-
-
- /*
- * ParentMessage method - OVERRIDE
- *
- * Handles kExpanderChildSelect message. When a parent notifies its children of a child
- * selection, the children should check to see if they have a positive selectedIndex value.
- * If so, then they should reset the value because they are not along the path of a selected
- * leaf node.
- */
-
- void CExpanderList :: ParentMessage( long message, void *param )
- {
- if ( message == kExpanderChildSelect ) {
- if ( selectedIndex > 0 ) // not in path of selected child
- selectedIndex = 0; // zap previous value
- }
-
- CExpander::ParentMessage( message, param ); // pass message on to superclass
- }
-
-
- /*
- * PutTo method - OVERRIDE
- *
- * Writes to the stream all the info we need to save.
- */
-
- void CExpanderList :: PutTo( CStream &stream )
- {
- stream << selectedIndex;
-
- CExpander::PutTo( stream );
- }
-
-
- /*
- * GetFrom method - OVERRIDE
- *
- * Reads from the stream all of the info that we saved.
- */
-
- void CExpanderList :: GetFrom( CStream &stream )
- {
- stream >> selectedIndex;
-
- CExpander::GetFrom( stream );
- }
-