home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Expander / Expander Classes / CRowColumnMgr.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  4.6 KB  |  164 lines  |  [TEXT/KAHL]

  1. /***********************************************************************************
  2.     CRowColumnMgr.cp
  3.  
  4.     Copyright © 1994 B-Ray Software. All rights reserved.
  5.     Developed using Symantec C++ 7.0 and Symantec's TCL library.
  6.     Portions of this code courtesy Symantec, Inc.
  7.  
  8.     This code may be freely distributed as long as this notice remains. The code
  9.     may not be used in any commercial software without the consent of B-Ray Software.
  10.  
  11.     ---
  12.  
  13.     Abstract class for child pane management. Basically, parent gets notified if
  14.     a child changes size. When a child does, the parent updates its own size to
  15.     reflect the new size of the family.
  16.  
  17. ***********************************************************************************/
  18.  
  19. #include "CRowColumnMgr.h"
  20.  
  21.  
  22. TCL_DEFINE_CLASS_M1( CRowColumnMgr, CFamily );
  23.  
  24.  
  25. /*
  26.  * AdjustForChildChange method
  27.  *
  28.  * Handles repositioning of children and resizing of ourselves
  29.  * when a child changes.
  30.  */
  31.  
  32. void CRowColumnMgr :: AdjustForChildChange( long changedIndex, Rect *delta )
  33. {
  34.     if ( delta->right || delta->bottom ) {
  35.         AdjustChildren( changedIndex, delta );    // reposition children
  36.         ChangeSelf( changedIndex, delta );        // adjust ourselves now
  37.         MakeChildrenValid( changedIndex );        // validate the areas that didn't change
  38.     }
  39. }
  40.  
  41.  
  42. /*
  43.  * AdjustChildren method
  44.  *
  45.  * Move the children up/down or left/right based on the delta contents.
  46.  * Actual movement is restricted by AdjustDelta, provided by derived
  47.  * classes.
  48.  */
  49.  
  50. void CRowColumnMgr :: AdjustChildren( long changedIndex, Rect *delta )
  51. {
  52.     CPane    *aChild;
  53.     long    index = GetNumberChildren();
  54.     Rect    rect = *delta;
  55.  
  56.     AdjustDelta( &rect );    // ignore irrelevant axis changes
  57.     if ( rect.right || rect.bottom ) {
  58.         while ( index > changedIndex ) {
  59.             aChild = GetChildAtIndex( index )->ChildToPane();    // get access to CPane data/methods
  60.             aChild->Prepare();                                    // ??? necessary ???
  61.             aChild->Offset( rect.right, rect.bottom, FALSE );    // move pane to new location
  62.             --index;
  63.         }
  64.     }
  65. }
  66.  
  67.  
  68. /*
  69.  * MakeChildrenValid method
  70.  *
  71.  * After resizing a child and resizing ourselves, we may have caused some children
  72.  * to be invalidated when they don't need to be. So, we walk thru our list of
  73.  * children and ValidRect() their frames so that they don't redraw and flicker (ugh!)
  74.  */
  75.  
  76. void CRowColumnMgr :: MakeChildrenValid( long changedIndex )
  77. {
  78.     CPane        *aChild;
  79.     LongRect    anAperture;
  80.     Rect        validRect;
  81.     long        index = 1;
  82.  
  83.     while ( index < changedIndex ) {
  84.         aChild = GetChildAtIndex( index )->ChildToPane();    // get access to CPane data/methods
  85.         aChild->Prepare();                                    // ??? necessary ???
  86.         aChild->GetAperture( &anAperture );                    // get the visible rectangle of the pane
  87.         aChild->FrameToQDR( &anAperture, &validRect );        // put into QD coordinates
  88.         ValidRect( &validRect );                            // tell Mac to ignore it on update
  89.         ++index;
  90.     }
  91. }
  92.  
  93.  
  94. /*
  95.  * InsertChildAt method - OVERRIDE
  96.  *
  97.  * Inserts a child into the list of children at the given index. May move
  98.  * other children panes.
  99.  */
  100.  
  101. void CRowColumnMgr :: InsertChildAt( CFamily *aChild, long index )
  102. {
  103.     Rect    delta = { 0, 0, 0, 0 };
  104.     CPane    *aPane = aChild->ChildToPane();    // gain access to CPane data/methods
  105.  
  106.     PositionChild( aPane, index );                // set pane at correct location within family
  107.  
  108.     CFamily::InsertChildAt( aChild, index );    // add child to list of children
  109.  
  110.     delta.bottom = aPane->height;                // calculate change child addition will have on others
  111.     delta.right = aPane->width;
  112.     AdjustForChildChange( index, &delta );        // cycle thru list of children and update their position 
  113. }
  114.  
  115.  
  116. /*
  117.  * RemoveChild method
  118.  *
  119.  * Removes a child pane from the family unit. Adjust other children if necessary
  120.  */
  121.  
  122. void CRowColumnMgr :: RemoveChild( CFamily *aChild )
  123. {
  124.     CPane    *aPane = aChild->ChildToPane();
  125.     long    index;
  126.     Rect    delta = { 0, 0, 0, 0 };
  127.     short    aWidth, aHeight;
  128.  
  129.     index = FindChildIndex( aChild );
  130.     if ( index > 0 ) {
  131.         itsChildren->DeleteItem( index );            // remove child from family
  132.         aChild->SetParent( NULL );                    // don't want to here from child anymore
  133.         aPane->GetLengths( &aWidth, &aHeight );        // set up change rect for rest of children
  134.         delta.bottom = -aHeight;
  135.         delta.right = -aWidth;
  136.         AdjustForChildChange( index - 1, &delta );    // revise position of other children
  137.     }
  138. }
  139.  
  140.  
  141. /*
  142.  * ChildMessage method - OVERRIDE
  143.  *
  144.  * Handles reception of kRowColChildChanged message sent by a member child.
  145.  */
  146.  
  147. void CRowColumnMgr :: ChildMessage( CFamily *aChild, long message, void *param )
  148. {
  149.     long    index;
  150.  
  151.     index = FindChildIndex( aChild );
  152.     if ( index > 0 ) {
  153.         switch ( message ) {
  154.             case kRowColChildChanged:    // update children with new positions
  155.                 AdjustForChildChange( index, (Rect *)param );
  156.                 break;
  157.  
  158.             default:                    // maybe ancestor class can handle it
  159.                 CFamily::ChildMessage( aChild, message, param );
  160.                 break;
  161.         }
  162.     }
  163. }
  164.