home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------------------------------------
- //
- // ColorBrowser
- //
- // Inherits From: NXBrowser
- //
- // Declared In: ColorBrowser.h
- //
- // Disclaimer
- //
- // You may freely copy, distribute and reuse this software and its
- // associated documentation. I disclaim any warranty of any kind,
- // expressed or implied, as to its fitness for any particular use.
- //
- //---------------------------------------------------------------------------------------------------------
- #import "ColorBrowser.h"
- #import "ColorBrowserCell.h"
-
-
- @implementation ColorBrowser
-
- //---------------------------------------------------------------------------------------------------------
- // Initialization
- //---------------------------------------------------------------------------------------------------------
- - initFrame: (const NXRect *) frameRect
- {
- // Give it default IB characteristics and set the Cell class.
-
- [super initFrame: frameRect];
- [self setCellClass: [ColorBrowserCell class]];
- [self separateColumns: YES];
- [self setHorizontalScrollerEnabled: YES];
- [self setEmptySelectionEnabled: YES];
- [self setTitle: "ColorBrowser" ofColumn: 0];
- return self;
- }
-
-
- //---------------------------------------------------------------------------------------------------------
- // Setting Cell Color
- //---------------------------------------------------------------------------------------------------------
- - setTextColor:(NXColor)aColor forCellWithStringValue:(const char*)aString inColumn:(int) aColumn
- {
- id matrix;
- id currentCell;
- int rows;
- int columns;
- int iterator;
-
- if ( ! aString) return self;
- if ( ! (matrix = [self matrixInColumn: aColumn])) return self;
-
- [matrix getNumRows: &rows numCols: &columns];
- if ( ! rows) return self;
-
- for (iterator = 0; iterator < rows; iterator++)
- {
- currentCell = [matrix cellAt: iterator : 0];
- if ( ! NXOrderStrings ( aString, [currentCell stringValue], YES, -1, NULL))
- [currentCell setTextColor: aColor];
- }
-
- [self update];
- return self;
- }
-
-
- - setTextColor: (NXColor) aColor forCellWithIntValue: (int) anInt inColumn: (int) aColumn
- {
- id matrix;
- int rows;
- int columns;
- int iterator;
-
- if ( ! (matrix = [self matrixInColumn: aColumn])) return self;
-
- [matrix getNumRows: &rows numCols: &columns];
- if ( ! rows) return self;
-
- for (iterator = 0; iterator < rows; iterator++)
- if ([[matrix cellAt: iterator : 0] intValue] == anInt)
- [[matrix cellAt: iterator : 0] setTextColor: aColor];
-
- [self update];
- return self;
- }
-
-
- - setTextColor: (NXColor) aColor forCellWithFloatValue: (float) aFloat inColumn: (int) aColumn
- {
- id matrix;
- int rows;
- int columns;
- int iterator;
-
- if ( ! (matrix = [self matrixInColumn: aColumn])) return self;
-
- [matrix getNumRows: &rows numCols: &columns];
- if ( ! rows) return self;
-
- for (iterator = 0; iterator < rows; iterator++)
- if ([[matrix cellAt: iterator : 0] floatValue] == aFloat)
- [[matrix cellAt: iterator : 0] setTextColor: aColor];
-
- [self update];
- return self;
- }
-
-
- - setTextColor: (NXColor)aColor forCellWithDoubleValue: (double)aDouble inColumn: (int) aColumn
- {
- id matrix;
- int rows;
- int columns;
- int iterator;
-
- if ( ! (matrix = [self matrixInColumn: aColumn])) return self;
-
- [matrix getNumRows: &rows numCols: &columns];
- if ( ! rows) return self;
-
- for (iterator = 0; iterator < rows; iterator++)
- if ([[matrix cellAt: iterator : 0] doubleValue] == aDouble)
- [[matrix cellAt: iterator : 0] setTextColor: aColor];
-
- [self update];
- return self;
- }
-
-
- - setTextColor: (NXColor) aColor forCellWithTag: (int) aTag inColumn: (int) aColumn
- {
- id matrix;
- id cellWithTag;
-
- if ( ! (matrix = [self matrixInColumn: aColumn])) return self;
- if ((cellWithTag = [matrix findCellWithTag: aTag]))
- [cellWithTag setTextColor: aColor];
-
- [self update];
- return self;
- }
-
-
- - setTextColor:(NXColor)aColor forCellInRow: (int) aRow inColumn: (int) aColumn;
- {
- id matrix;
- id cellInRow;
-
- if ( ! (matrix = [self matrixInColumn: aColumn])) return self;
- if ((cellInRow = [matrix cellAt: aRow :0]))
- [cellInRow setTextColor: aColor];
-
- [self update];
- return self;
- }
-
-
- - setTextColor: (NXColor) aColor inColumn: (int) aColumn;
- {
- id matrix;
- int rows;
- int columns;
- int iterator;
-
- if ( ! (matrix = [self matrixInColumn: aColumn])) return self;
-
- [matrix getNumRows: &rows numCols: &columns];
- if ( ! rows) return self;
-
- for (iterator = 0; iterator < rows; iterator++)
- [[matrix cellAt: iterator :0] setTextColor: aColor];
-
- [self update];
- return self;
- }
-
-
- - setTextColorOfSelectedCells:(NXColor)aColor
- {
- if ([self isMultipleSelectionEnabled])
- {
- int iterator;
- id selectedCellsList = [[List alloc] init];
- [self getSelectedCells: selectedCellsList];
-
- for (iterator = 0; iterator < [selectedCellsList count]; iterator++)
- [[selectedCellsList objectAt: iterator] setTextColor: aColor];
-
- if (selectedCellsList) [selectedCellsList free];
- }
- else
- {
- [[self selectedCell] setTextColor: aColor];
- }
-
- [self update];
- return self;
- }
-
-
- //---------------------------------------------------------------------------------------------------------
- // IB Methods
- //---------------------------------------------------------------------------------------------------------
- - (const char*) getInspectorClassName
- {
- return "ColorBrowserInspector";
- }
-
-
- @end