From a6ee37e03035001ea83d0863c6284c7922e6a59c Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Mon, 30 May 2011 00:56:28 -0400 Subject: [PATCH] Support level indicators as table cells through nib2cib. --- AppKit/CPTableView.j | 3 +-- Tools/nib2cib/NSLevelIndicator.j | 30 ++++++++++++++++++++++-------- Tools/nib2cib/NSTableColumn.j | 5 +++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 104b292db..c2f28dcf9 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -1544,7 +1544,6 @@ NOT YET IMPLEMENTED _numberOfHiddenColumns += 1; _tableColumnRanges[index] = CPMakeRange(x, 0.0); } - else { var width = [_tableColumns[index] width] + _intercellSpacing.width; @@ -1843,7 +1842,7 @@ NOT YET IMPLEMENTED leftInset = FLOOR(_intercellSpacing.width / 2.0), topInset = FLOOR(_intercellSpacing.height / 2.0); - return _CGRectMake(tableColumnRange.location + leftInset, _CGRectGetMinY(rectOfRow) + topInset, tableColumnRange.length - _intercellSpacing.width, _CGRectGetHeight(rectOfRow) - _intercellSpacing.height); + return _CGRectMake(tableColumnRange.location + leftInset, _CGRectGetMinY(rectOfRow) + topInset, tableColumnRange.length - _intercellSpacing.width, _CGRectGetHeight(rectOfRow) - _intercellSpacing.height); } /*! diff --git a/Tools/nib2cib/NSLevelIndicator.j b/Tools/nib2cib/NSLevelIndicator.j index e62a62d19..172915429 100644 --- a/Tools/nib2cib/NSLevelIndicator.j +++ b/Tools/nib2cib/NSLevelIndicator.j @@ -28,6 +28,7 @@ { var cell = [aCoder decodeObjectForKey:@"NSCell"]; + // Initialise before [super ...] to ensure setObjectValue constrains the values properly. _minValue = [cell minValue]; _maxValue = [cell maxValue]; @@ -35,19 +36,32 @@ if (self) { - _levelIndicatorStyle = [cell levelIndicatorStyle]; - _warningValue = [cell warningValue]; - _criticalValue = [cell criticalValue]; - _tickMarkPosition = [cell tickMarkPosition]; - _numberOfTickMarks = [cell numberOfTickMarks]; - _numberOfMajorTickMarks = [cell numberOfMajorTickMarks]; - - [self setEditable:[cell isEditable]]; + self = [self NS_initWithCell:cell]; } return self; } +/*! + Intialise the receiver given a cell. This method is meant for reuse by controls which contain + cells other than CPLevelIndicator itself. +*/ +- (id)NS_initWithCell:(NSCell)cell +{ + _minValue = [cell minValue]; + _maxValue = [cell maxValue]; + _levelIndicatorStyle = [cell levelIndicatorStyle]; + _warningValue = [cell warningValue]; + _criticalValue = [cell criticalValue]; + _tickMarkPosition = [cell tickMarkPosition]; + _numberOfTickMarks = [cell numberOfTickMarks]; + _numberOfMajorTickMarks = [cell numberOfMajorTickMarks]; + + [self setEditable:[cell isEditable]]; + + return self; +} + @end @implementation NSLevelIndicator : CPLevelIndicator diff --git a/Tools/nib2cib/NSTableColumn.j b/Tools/nib2cib/NSTableColumn.j index adf0ae598..f573c29f8 100644 --- a/Tools/nib2cib/NSTableColumn.j +++ b/Tools/nib2cib/NSTableColumn.j @@ -78,6 +78,11 @@ _dataView = [[CPButton alloc] initWithFrame:CGRectMakeZero()]; _dataView = [_dataView NS_initWithCell:dataViewCell]; } + else if ([dataViewCell isKindOfClass:[NSLevelIndicatorCell class]]) + { + _dataView = [[CPLevelIndicator alloc] initWithFrame:CGRectMakeZero()]; + _dataView = [_dataView NS_initWithCell:dataViewCell]; + } [_dataView setValue:[dataViewCell alignment] forThemeAttribute:@"alignment"];