home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / Palettes / ColorBrowser / ColorBrowser.m < prev    next >
Text File  |  1993-01-19  |  5KB  |  211 lines

  1. //---------------------------------------------------------------------------------------------------------
  2. //
  3. //    ColorBrowser
  4. //
  5. //    Inherits From:        NXBrowser
  6. //
  7. //    Declared In:        ColorBrowser.h
  8. //
  9. //    Disclaimer
  10. //
  11. //        You may freely copy, distribute and reuse this software and its
  12. //        associated documentation. I disclaim any warranty of any kind, 
  13. //        expressed or implied, as to its fitness for any particular use.
  14. //
  15. //---------------------------------------------------------------------------------------------------------
  16. #import "ColorBrowser.h"
  17. #import "ColorBrowserCell.h"
  18.  
  19.  
  20. @implementation ColorBrowser
  21.  
  22. //---------------------------------------------------------------------------------------------------------
  23. //     Initialization
  24. //---------------------------------------------------------------------------------------------------------
  25. - initFrame: (const NXRect *) frameRect
  26. {
  27.     //  Give it default IB characteristics and set the Cell class.
  28.     
  29.     [super initFrame: frameRect];
  30.     [self setCellClass: [ColorBrowserCell class]];
  31.     [self separateColumns: YES];
  32.     [self setHorizontalScrollerEnabled: YES];
  33.     [self setEmptySelectionEnabled: YES];
  34.     [self setTitle: "ColorBrowser" ofColumn: 0];
  35.     return self;
  36. }
  37.  
  38.  
  39. //---------------------------------------------------------------------------------------------------------
  40. //     Setting Cell Color
  41. //---------------------------------------------------------------------------------------------------------
  42. - setTextColor:(NXColor)aColor forCellWithStringValue:(const char*)aString inColumn:(int) aColumn
  43. {
  44.     id    matrix;
  45.     id    currentCell;    
  46.     int    rows;
  47.     int    columns;
  48.     int    iterator;
  49.     
  50.     if ( ! aString) return self;
  51.     if ( ! (matrix  = [self matrixInColumn: aColumn])) return self;
  52.     
  53.     [matrix getNumRows: &rows  numCols: &columns];
  54.     if ( ! rows) return self;
  55.     
  56.     for (iterator = 0; iterator < rows; iterator++)
  57.         {
  58.         currentCell = [matrix cellAt: iterator : 0];
  59.         if ( ! NXOrderStrings ( aString, [currentCell stringValue], YES, -1, NULL))
  60.             [currentCell setTextColor: aColor];
  61.         }
  62.         
  63.     [self update];
  64.     return self;
  65. }
  66.  
  67.  
  68. - setTextColor: (NXColor) aColor  forCellWithIntValue: (int) anInt  inColumn: (int) aColumn
  69. {
  70.     id    matrix;
  71.     int    rows;
  72.     int    columns;
  73.     int    iterator;
  74.     
  75.     if ( ! (matrix  = [self matrixInColumn: aColumn])) return self;
  76.     
  77.     [matrix getNumRows: &rows  numCols: &columns];
  78.     if ( ! rows) return self;
  79.     
  80.     for (iterator = 0; iterator < rows; iterator++)
  81.         if ([[matrix cellAt: iterator : 0] intValue] == anInt) 
  82.             [[matrix cellAt: iterator : 0] setTextColor: aColor];
  83.         
  84.     [self update];
  85.     return self;
  86. }
  87.  
  88.  
  89. - setTextColor: (NXColor) aColor  forCellWithFloatValue: (float) aFloat  inColumn: (int) aColumn
  90. {
  91.     id    matrix;
  92.     int    rows;
  93.     int    columns;
  94.     int    iterator;
  95.     
  96.     if ( ! (matrix  = [self matrixInColumn: aColumn])) return self;
  97.     
  98.     [matrix getNumRows: &rows  numCols: &columns];
  99.     if ( ! rows) return self;
  100.     
  101.     for (iterator = 0; iterator < rows; iterator++)
  102.         if ([[matrix cellAt: iterator : 0] floatValue] == aFloat) 
  103.             [[matrix cellAt: iterator : 0] setTextColor: aColor];
  104.         
  105.     [self update];
  106.     return self;
  107. }
  108.  
  109.  
  110. - setTextColor: (NXColor)aColor  forCellWithDoubleValue: (double)aDouble  inColumn: (int) aColumn
  111. {
  112.     id    matrix;
  113.     int    rows;
  114.     int    columns;
  115.     int    iterator;
  116.     
  117.     if ( ! (matrix  = [self matrixInColumn: aColumn])) return self;
  118.     
  119.     [matrix getNumRows: &rows  numCols: &columns];
  120.     if ( ! rows) return self;
  121.     
  122.     for (iterator = 0; iterator < rows; iterator++)
  123.         if ([[matrix cellAt: iterator : 0] doubleValue] == aDouble) 
  124.             [[matrix cellAt: iterator : 0] setTextColor: aColor];
  125.         
  126.     [self update];
  127.     return self;
  128. }
  129.  
  130.  
  131. - setTextColor: (NXColor) aColor  forCellWithTag: (int) aTag  inColumn: (int) aColumn
  132. {
  133.     id    matrix;
  134.     id    cellWithTag;
  135.     
  136.     if ( ! (matrix  = [self matrixInColumn: aColumn])) return self;
  137.     if ((cellWithTag = [matrix findCellWithTag: aTag])) 
  138.         [cellWithTag setTextColor: aColor];
  139.         
  140.     [self update];
  141.     return self;
  142. }
  143.  
  144.  
  145. - setTextColor:(NXColor)aColor forCellInRow: (int) aRow  inColumn: (int) aColumn;
  146. {
  147.     id    matrix;
  148.     id    cellInRow;
  149.     
  150.     if ( ! (matrix  = [self matrixInColumn: aColumn])) return self;
  151.     if ((cellInRow = [matrix cellAt: aRow :0])) 
  152.         [cellInRow setTextColor: aColor];
  153.         
  154.     [self update];
  155.     return self;
  156. }
  157.  
  158.  
  159. - setTextColor: (NXColor) aColor  inColumn: (int) aColumn;
  160. {
  161.     id    matrix;
  162.     int    rows;
  163.     int    columns;
  164.     int    iterator;
  165.     
  166.     if ( ! (matrix  = [self matrixInColumn: aColumn])) return self;
  167.     
  168.     [matrix getNumRows: &rows  numCols: &columns];
  169.     if ( ! rows) return self;
  170.     
  171.     for (iterator = 0; iterator < rows; iterator++)
  172.         [[matrix cellAt: iterator  :0] setTextColor: aColor];
  173.         
  174.     [self update];
  175.     return self;
  176. }
  177.  
  178.  
  179. - setTextColorOfSelectedCells:(NXColor)aColor
  180. {
  181.     if ([self isMultipleSelectionEnabled])
  182.         {
  183.         int    iterator;
  184.         id      selectedCellsList = [[List alloc] init];
  185.         [self getSelectedCells: selectedCellsList];
  186.  
  187.         for (iterator = 0; iterator < [selectedCellsList count]; iterator++)
  188.             [[selectedCellsList objectAt: iterator] setTextColor: aColor];
  189.  
  190.         if (selectedCellsList) [selectedCellsList free];
  191.         }
  192.     else
  193.         {
  194.         [[self selectedCell] setTextColor: aColor];
  195.         }
  196.         
  197.     [self update];
  198.     return self;
  199. }
  200.     
  201.         
  202. //---------------------------------------------------------------------------------------------------------
  203. //     IB Methods
  204. //---------------------------------------------------------------------------------------------------------
  205. - (const char*) getInspectorClassName
  206. {
  207.     return "ColorBrowserInspector";
  208. }
  209.  
  210.  
  211. @end