home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / SourceCode / MiniExamples / CellScrollView / Controller.m < prev    next >
Encoding:
Text File  |  1991-09-10  |  1.6 KB  |  76 lines

  1. /* You may freely copy, distribute, and reuse the code in this example.
  2.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  3.  * fitness for any particular use.
  4.  */
  5.  
  6.  
  7. #import "Controller.h"
  8. #import <objc/List.h>
  9. #import <appkit/Matrix.h>
  10. #import "FooObject.h"
  11. #import "CellScrollView.h"
  12. #import "FooCell.h"
  13.  
  14. @implementation Controller
  15.  
  16. - appDidInit:sender
  17. {
  18.   [self addFooObject:self];
  19.   [cellScrollView loadCellsFrom:fooObjects];
  20.   cellMatrix = [cellScrollView cellMatrix];
  21.   return self;
  22. }
  23.  
  24. - init
  25. {
  26.   [super init];
  27.   fooObjects = [[List alloc] init];
  28.   return self;
  29. }
  30.  
  31. - free
  32. {
  33.   [fooObjects free];
  34.   return [super free];
  35. }
  36.  
  37. - addFooObject:sender
  38. {
  39.   FooObject *fooObject = [[FooObject alloc] init];
  40.   [fooObjects addObject:fooObject];
  41.   [cellScrollView loadCellsFrom:fooObjects];
  42.   /*
  43.    * Assumptions in this next line:
  44.    *    There are as many fooCells as there are fooObjects
  45.    *    We've added the new fooObject at the end of the list.
  46.    *    We want to display the fooObject we just added and highlight it.
  47.    * In short, this is a hack.
  48.    */
  49.   [cellMatrix scrollCellToVisible:[fooObjects count]-1 :0];
  50.   [cellMatrix selectCellAt:[fooObjects count]-1:0];
  51.   return self;
  52. }
  53.  
  54. - deleteFooObjects:sender
  55. /*
  56.  * Delete all selected fooObjects.
  57.  */
  58. {
  59.   int i;
  60.  
  61.   for (i=[cellMatrix cellCount]-1; i>=0; i--) {
  62.     FooCell *cell = [cellMatrix cellAt:i:0];
  63.     if ([cell isHighlighted]) {
  64.       /*
  65.        * If a cell is highlighted, remove (and free) the corresponding item
  66.        * from the list of fooObjects.
  67.        */
  68.       [[fooObjects removeObject:[cell fooObject]] free];
  69.     }
  70.   }
  71.   [cellScrollView loadCellsFrom:fooObjects];
  72.   return self;
  73. }
  74.  
  75. @end
  76.