home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / DynamicApp / AutoWidthMatrix.m < prev    next >
Text File  |  1993-01-19  |  2KB  |  60 lines

  1. #import "AutoWidthMatrix.h"
  2.  
  3. @implementation AutoWidthMatrix
  4.  
  5. - superviewSizeChanged:(const NXSize *) oldSize
  6. {
  7.    [self sizeToSuperviewWidth];
  8.    return self;
  9. }
  10.  
  11. - sizeToSuperviewWidth
  12. {
  13.    /* Matix instance variables used:
  14.       NXSize cellSize
  15.       NXSize intercell
  16.       int numCols */
  17.  
  18.    NXRect r;            /* superview's frame */
  19.    float newWidth, newHeight;
  20.  
  21.    if (! [self superview]) return self;
  22.    
  23.    [[self superview] getFrame:&r];
  24.  
  25.    /* The matrix width will be the same as the superview's width. */
  26.  
  27.    newWidth = r.size.width;
  28.  
  29.    /* The matrix height is computed by multiplying the total height of one
  30.       cell (this includes any intercell gap) by the number of rows.
  31.  
  32.       One intercell gap is subtracted because there is not intercell space
  33.       before the first cell or after the last.  (The other Matrix methods,
  34.       SizeToFit and SizeTo, seem to also follow this rule.) */
  35.  
  36.    newHeight = numRows * (intercell.height + cellSize.height)
  37.       - intercell.height;
  38.  
  39.    if (newHeight < 0.0) newHeight = 0.0;
  40.  
  41.    /* The cell width is computed so that the matrix columns fill up the
  42.       available superview width.  (If the superview width is small and the
  43.       number of columns large, this will result in rather small cells.)
  44.  
  45.       The formula computes the space available for cells by taking the
  46.       amount of width available, subtracting out the space required for
  47.       intercell gaps, and dividing this between the number of columns.
  48.       (One extra intercell gap is returned to the available space because
  49.       the gaps are between cells, not at the end or beginning of cells.) */
  50.  
  51.    cellSize.width  = (r.size.width - (intercell.width * numCols)
  52.               + intercell.width) / numCols;
  53.  
  54.    [self sizeTo:newWidth :newHeight];
  55.    
  56.    return self;
  57. }
  58.    
  59. @end
  60.