AppKit: Replace legacy CPTableView rendering with view-backed rows and decoration views

Replace the legacy table view rendering methods with a view-backed architecture.
CPTableView now performs no drawing in -drawRect: by default. Subclasses
overriding a layer drawing method (background, selection, grid, or rows)
have that layer and all foreground layers drawn onto a canvas subview,
while column selection and vertical grid lines are presented as views within
a decoration container.

Row views display the state assigned by the table view. Calling
-setNeedsDisplay: flags visual invalidation, prompting the subsequent layout
pass to reconfigure visible row views. Visible rows remain synchronized during
layout, and the rendering state is invalidated whenever rows, columns, or the
exposed rect change.

- Aristo2: Define a group row background color.
- CPTableViewDrawingPassTest: Add unit tests covering the drawing pass.
This commit is contained in:
David Richardson committed 2026-11-18 09:47:58 -06:00
1 parent c41b4d5235
commit 0111408d5f
14 files changed
+1718 -275

No files matched your search

+1 -1
View File
@@ -1941,7 +1941,7 @@ function SHOULD_SELECT_ITEM(anOutlineView, anItem)
{
if (_dropItem)
{
[_dropOperationFeedbackView blink];
[self _blinkDropTargetRowView];
[CPTimer scheduledTimerWithTimeInterval:.3 callback:[self expandItem:_dropItem] repeats:NO];
}
};
+9 -1
View File
@@ -925,7 +925,15 @@ var CPTableHeaderViewResizeZone = 3.0,
[_tableView _loadDataViewsInRows:rowsIndexes columns:columnsIndexes];
[_tableView _layoutViewsForRowIndexes:rowsIndexes columnIndexes:columnsIndexes];
[_tableView _updateDataViewsFocusState];
[_tableView._tableDrawView displayRect:columnVisRect];
/*
The header view displayed the table view's canvas through an instance variable that
the table view no longer has, so nothing drew again after a column drag. The table
view marks the canvas of its drawing pass, when it has one, and lays out its column
selection and grid lines again.
*/
[_tableView _markDrawingPassForDisplay];
[_tableView setNeedsLayout];
[[CPCursor arrowCursor] set]; // FIXME: retirer ?
[self updateTrackingAreas];
+563 -21
View File
@@ -24,6 +24,11 @@
@class CPTableView
/*
YES for each row view class that draws on a canvas, by class UID.
*/
var CPTableRowViewDrawsOnCanvasForClasses = { };
/*!
@ingroup appkit
@@ -46,6 +51,14 @@
In Cappuccino the views of a row are subviews of the table view, not of the row view. The
row view lies behind the views of its row and spans the full width of the table view.
A row view takes no mouse events.
The row view draws the standard look with CSS. A subclass that overrides \c drawRect: or
one of the four draw methods draws on a canvas instead: its \c drawRect: calls
\c drawBackgroundInRect:, \c drawSelectionInRect: when the row is selected,
\c drawSeparatorInRect: when the table view's grid style has horizontal lines, and
\c drawDraggingDestinationFeedbackInRect: when a drag proposes a drop on the row, in that
order. The four methods draw the standard look on the current graphics context, so an
override can call super.
*/
@implementation CPTableRowView : CPView
{
@@ -65,8 +78,47 @@
CPTableView _tableView;
BOOL _isMadeByTableView;
BOOL _isFillerRow;
BOOL _isDropFeedbackHiddenForBlink;
CPView _selectionView;
CPView _selectionLineView;
CPView _separatorView;
CPView _dropFeedbackView;
}
/*
Returns YES when the receiver overrides drawRect: or one of the four draw methods. Its
instances then draw on a canvas, and the CSS parts of the standard look are off.
*/
+ (BOOL)_drawsOnCanvas
{
var UID = [self UID],
drawsOnCanvas = CPTableRowViewDrawsOnCanvasForClasses[UID];
if (drawsOnCanvas === undefined)
{
var selectors = [@selector(drawRect:), @selector(drawBackgroundInRect:), @selector(drawSelectionInRect:),
@selector(drawSeparatorInRect:), @selector(drawDraggingDestinationFeedbackInRect:)];
drawsOnCanvas = NO;
for (var i = 0; i < selectors.length && !drawsOnCanvas; i++)
drawsOnCanvas = [self instanceMethodForSelector:selectors[i]] !== [CPTableRowView instanceMethodForSelector:selectors[i]];
CPTableRowViewDrawsOnCanvasForClasses[UID] = drawsOnCanvas;
}
return drawsOnCanvas;
}
/*
A row view of a class that does not draw on a canvas takes no display marks, although
CPTableRowView implements drawRect:. Otherwise every row view would receive drawRect: at
each change of its state.
*/
+ (BOOL)_hasCustomDrawRect
{
return [self _drawsOnCanvas] || [self instanceMethodForSelector:@selector(viewWillDraw)] !== [CPView instanceMethodForSelector:@selector(viewWillDraw)];
}
- (id)initWithFrame:(CGRect)aFrame
@@ -381,27 +433,186 @@
}
/*
Writes the look of the row: the selection colour for a selected row, else the background
colour; and the horizontal separator at the bottom edge when the table view's grid style
has horizontal lines and the row is not a group row.
Returns the state of the row, in the form that the look rules read.
*/
- (Object)_rowState
{
return {
selected: _selected,
emphasized: _emphasized,
groupRowStyle: _groupRowStyle,
selectionHighlightStyle: _selectionHighlightStyle,
nextRowSelected: _nextRowSelected,
targetForDropOperation: _targetForDropOperation && !_isDropFeedbackHiddenForBlink,
draggingDestinationFeedbackStyle: _draggingDestinationFeedbackStyle,
indentationForDropOperation: _indentationForDropOperation,
backgroundColor: _rowBackgroundColor,
defaultBackgroundColor: _defaultRowBackgroundColor
};
}
/*
Returns the layers that the table view's drawing pass draws in place of the row view.
*/
- (unsigned)_drawingPassLayers
{
return [_tableView _drawingPassLayers] || 0;
}
// MARK: Drawing on a canvas
/*!
Draws the row, for a subclass that overrides this method or one of the four draw methods.
It calls \c drawBackgroundInRect:, then \c drawSelectionInRect: when the row is selected
and the selection highlight style is not None, then \c drawSeparatorInRect: when the table
view's grid style has horizontal lines, then \c drawDraggingDestinationFeedbackInRect:
when a drag proposes a drop on the row. A part that the table view's drawing pass draws is
left out.
A row view of the base class draws with CSS and receives no \c drawRect:.
*/
- (void)drawRect:(CGRect)aRect
{
if (![[self class] _drawsOnCanvas])
return;
var passLayers = [self _drawingPassLayers];
if (!(passLayers & _CPTableViewDrawingLayerBackground))
[self drawBackgroundInRect:aRect];
if (_selected && _selectionHighlightStyle !== CPTableViewSelectionHighlightStyleNone && !(passLayers & _CPTableViewDrawingLayerSelection))
[self drawSelectionInRect:aRect];
if (([_tableView gridStyleMask] & CPTableViewSolidHorizontalGridLineMask) && !(passLayers & _CPTableViewDrawingLayerGrid))
[self drawSeparatorInRect:aRect];
if (_targetForDropOperation && !_isDropFeedbackHiddenForBlink)
[self drawDraggingDestinationFeedbackInRect:aRect];
}
/*!
Draws the background of the row on the current graphics context: the background colour,
or the group row colour for a group row. A subclass overrides this method to draw another
background.
*/
- (void)drawBackgroundInRect:(CGRect)aRect
{
[CPTableRowView _drawBackgroundOfLook:[self _look] inRect:[self bounds]];
}
/*!
Draws the selection of the row on the current graphics context, in the table view's
selection highlight style. The row view calls this method only for a selected row.
*/
- (void)drawSelectionInRect:(CGRect)aRect
{
[CPTableRowView _drawSelectionOfLook:[self _look] inRect:[self bounds]];
}
/*!
Draws the horizontal separator at the bottom edge of the row on the current graphics
context. The row view calls this method only when the table view's grid style has
horizontal lines. A group row has no separator.
*/
- (void)drawSeparatorInRect:(CGRect)aRect
{
[CPTableRowView _drawSeparatorOfLook:[self _look] inRect:[self bounds]];
}
/*!
Draws the feedback for a drop on the row on the current graphics context. The row view
calls this method only when a drag proposes a drop on the row.
*/
- (void)drawDraggingDestinationFeedbackInRect:(CGRect)aRect
{
[CPTableRowView _drawDropFeedbackOfLook:[self _look] inRect:[self bounds]];
}
- (Object)_look
{
return [CPTableRowView _lookForTableView:_tableView rowState:[self _rowState]];
}
// MARK: Drawing with CSS
/*
Writes the look of the row in CSS, under the row view's effective appearance: the
background colour of the row view itself, then a child view for each other part, made at
first use: the selection, the horizontal separator and the feedback for a drop. A part
that the table view's drawing pass draws is off. A row view that draws on a canvas has no
CSS parts.
*/
- (void)layoutSubviews
{
var color = nil;
if ([[self class] _drawsOnCanvas])
{
[super setBackgroundColor:nil];
[_selectionView setHidden:YES];
[_separatorView setHidden:YES];
[_dropFeedbackView setHidden:YES];
if (_selected && _selectionHighlightStyle !== CPTableViewSelectionHighlightStyleNone)
color = _emphasized ? [_tableView selectionHighlightColor] : [_tableView unfocusedSelectionHighlightColor];
else
color = _rowBackgroundColor || _defaultRowBackgroundColor;
return;
}
[super setBackgroundColor:color];
var look = [self _look],
passLayers = [self _drawingPassLayers];
[self _layoutSeparator];
[super setBackgroundColor:(passLayers & _CPTableViewDrawingLayerBackground) ? nil : look.backgroundColor];
[self _layoutSelection:(passLayers & _CPTableViewDrawingLayerSelection) ? nil : look.selection
bottomLineColor:look.selectionBottomLineColor];
[self _layoutSeparator:(passLayers & _CPTableViewDrawingLayerGrid) ? nil : look.separator];
[self _layoutDropFeedback:look.drop];
}
- (void)_layoutSeparator
/*
The selection: one child view over the whole row, behind the other parts. When the next
row is selected too, a line at the bottom edge separates the two selections.
*/
- (void)_layoutSelection:(Object)aSelection bottomLineColor:(CPColor)aLineColor
{
if (_groupRowStyle || !([_tableView gridStyleMask] & CPTableViewSolidHorizontalGridLineMask))
if (!aSelection)
{
[_selectionView setHidden:YES];
return;
}
var bounds = [self bounds];
if (!_selectionView)
{
_selectionView = [self _newPartView];
[self addSubview:_selectionView positioned:CPWindowBelow relativeTo:nil];
}
[_selectionView setFrame:bounds];
[_selectionView setBackgroundColor:[CPTableRowView _CSSColorForSelection:aSelection]];
[_selectionView setHidden:NO];
if (!aLineColor)
{
[_selectionLineView setHidden:YES];
return;
}
if (!_selectionLineView)
{
_selectionLineView = [self _newPartView];
[_selectionView addSubview:_selectionLineView];
}
[_selectionLineView setFrame:CGRectMake(0.0, CGRectGetHeight(bounds) - 1.0, CGRectGetWidth(bounds), 1.0)];
[_selectionLineView setBackgroundColor:aLineColor];
[_selectionLineView setHidden:NO];
}
/*
The horizontal separator: one child view at the bottom edge, in front of the selection.
*/
- (void)_layoutSeparator:(Object)aSeparator
{
if (!aSeparator)
{
[_separatorView setHidden:YES];
return;
@@ -409,20 +620,61 @@
if (!_separatorView)
{
_separatorView = [[CPView alloc] initWithFrame:CGRectMakeZero()];
[_separatorView setHitTests:NO];
[_separatorView setAutoresizingMask:CPViewWidthSizable | CPViewMinYMargin];
[self addSubview:_separatorView];
_separatorView = [self _newPartView];
if (_dropFeedbackView)
[self addSubview:_separatorView positioned:CPWindowBelow relativeTo:_dropFeedbackView];
else
[self addSubview:_separatorView];
}
var thickness = [_tableView valueForThemeAttribute:@"grid-line-thickness"] || 1.0,
bounds = [self bounds];
[_separatorView setBackgroundColor:[_tableView gridColor]];
[_separatorView setFrame:CGRectMake(0.0, CGRectGetHeight(bounds) - thickness, CGRectGetWidth(bounds), thickness)];
[_separatorView setFrame:[CPTableRowView _separatorRectOfLook:aSeparator inRect:[self bounds]]];
[_separatorView setBackgroundColor:aSeparator.color];
[_separatorView setHidden:NO];
}
/*
The feedback for a drop on the row: one child view in front of the other parts.
*/
- (void)_layoutDropFeedback:(Object)aDrop
{
if (!aDrop)
{
[_dropFeedbackView setHidden:YES];
return;
}
if (!_dropFeedbackView)
{
_dropFeedbackView = [self _newPartView];
[self addSubview:_dropFeedbackView];
}
var css = @{ @"box-sizing": @"border-box" };
if (aDrop.backgroundColor)
[css setObject:aDrop.backgroundColor forKey:@"background-color"];
if (aDrop.borderColor && aDrop.borderWidth)
[css setObject:[aDrop.borderWidth + "px solid ", aDrop.borderColor] forKey:@"border"];
if (aDrop.borderRadius)
[css setObject:aDrop.borderRadius + "px" forKey:@"border-radius"];
[_dropFeedbackView setFrame:[CPTableRowView _dropFeedbackRectOfLook:aDrop inRect:[self bounds]]];
[_dropFeedbackView setBackgroundColor:[CPColor colorWithCSSDictionary:css]];
[_dropFeedbackView setHidden:NO];
}
- (CPView)_newPartView
{
var view = [[CPView alloc] initWithFrame:CGRectMakeZero()];
[view setHitTests:NO];
return view;
}
@end
@@ -489,6 +741,296 @@
{
_rowBackgroundColor = nil;
_targetForDropOperation = NO;
_isDropFeedbackHiddenForBlink = NO;
}
/*
Blinks the feedback for a drop on the row, before an outline view expands the item that
the drag hovers over.
*/
- (void)_blinkDraggingDestinationFeedback
{
if (!_targetForDropOperation)
return;
var setHidden = function(isHidden)
{
_isDropFeedbackHiddenForBlink = isHidden;
[self _rowStateDidChange];
};
setHidden(YES);
[CPTimer scheduledTimerWithTimeInterval:0.1 callback:function() { setHidden(NO); } repeats:NO];
[CPTimer scheduledTimerWithTimeInterval:0.19 callback:function() { setHidden(YES); } repeats:NO];
[CPTimer scheduledTimerWithTimeInterval:0.27 callback:function() { setHidden(NO); } repeats:NO];
}
@end
/*
The look of a row: one set of rules, read by the CSS renderer of a row view, by the canvas
renderer of a row view that draws on a canvas, and by the table view's default drawing
methods.
*/
@implementation CPTableRowView (CPTableRowLook)
/*
Returns the resolved look of a row in aTableView with aState, the state of a row view
(see -_rowState). Each part is nil when the row does not show it:
- backgroundColor: the colour that the application set on the row view, else the default
that the table view gives (the group row colour outside the source-list style, else the
alternating colour of the row), else nil, so that the table view's background shows.
- selection: for a selected row whose style is not None. In the source-list style, the
gradient of the source-list selection colour with its top and bottom line colours; else
the selection colour with the selection radius. Without the emphasized look, the
unfocused variants.
- selectionBottomLineColor: the highlighted grid colour, when the next row is selected too.
- separator: the grid colour and line thickness, when the grid style has horizontal lines
and the row is not a group row.
- drop: the colours, border and radius of the feedback for a drop on the row, with the
selected variants for a selected row, and the indentation of the drop.
*/
+ (Object)_lookForTableView:(CPTableView)aTableView rowState:(Object)aState
{
var look = {
backgroundColor: aState.backgroundColor || aState.defaultBackgroundColor || nil,
selection: nil,
selectionBottomLineColor: nil,
separator: nil,
drop: nil
};
if (aState.selected && aState.selectionHighlightStyle !== CPTableViewSelectionHighlightStyleNone)
{
if (aState.selectionHighlightStyle === CPTableViewSelectionHighlightStyleSourceList && [aTableView selectionGradientColors])
{
var colors = aState.emphasized ? [aTableView selectionGradientColors] : [aTableView unfocusedSelectionGradientColors],
gradient = [colors objectForKey:CPSourceListGradient];
if (gradient)
look.selection = {
gradient: gradient,
topLineColor: [colors objectForKey:CPSourceListTopLineColor],
bottomLineColor: [colors objectForKey:CPSourceListBottomLineColor]
};
}
if (!look.selection)
{
var color = aState.emphasized ? [aTableView selectionHighlightColor] : [aTableView unfocusedSelectionHighlightColor];
if (color)
look.selection = {
color: color,
radius: [aTableView currentValueForThemeAttribute:@"selection-radius"] || 0.0
};
}
if (look.selection && aState.nextRowSelected)
look.selectionBottomLineColor = [aTableView currentValueForThemeAttribute:@"highlighted-grid-color"];
}
if (!aState.groupRowStyle && ([aTableView gridStyleMask] & CPTableViewSolidHorizontalGridLineMask) && [aTableView gridColor])
look.separator = {
color: [aTableView gridColor],
thickness: [aTableView currentValueForThemeAttribute:@"grid-line-thickness"] || 1.0
};
if (aState.targetForDropOperation && aState.draggingDestinationFeedbackStyle !== CPTableViewDraggingDestinationFeedbackStyleNone)
{
var prefix = aState.selected ? @"dropview-on-selected-" : @"dropview-on-";
look.drop = {
backgroundColor: [aTableView currentValueForThemeAttribute:prefix + @"background-color"],
borderColor: [aTableView currentValueForThemeAttribute:prefix + @"border-color"],
borderWidth: [aTableView currentValueForThemeAttribute:prefix + @"border-width"] || 0.0,
borderRadius: [aTableView currentValueForThemeAttribute:prefix + @"border-radius"] || 0.0,
indentation: aState.indentationForDropOperation || 0.0
};
}
return look;
}
/*
Returns the rect of a separator at the bottom edge of aRect, a row rect.
*/
+ (CGRect)_separatorRectOfLook:(Object)aSeparator inRect:(CGRect)aRect
{
return CGRectMake(CGRectGetMinX(aRect), CGRectGetMaxY(aRect) - aSeparator.thickness, CGRectGetWidth(aRect), aSeparator.thickness);
}
/*
Returns the rect of the feedback for a drop in aRect, a row rect: inset by 2 points, less
3 points at the bottom, and shifted right by the indentation of the drop.
*/
+ (CGRect)_dropFeedbackRectOfLook:(Object)aDrop inRect:(CGRect)aRect
{
return CGRectMake(CGRectGetMinX(aRect) + 2.0 + aDrop.indentation,
CGRectGetMinY(aRect) + 2.0,
MAX(0.0, CGRectGetWidth(aRect) - 4.0 - aDrop.indentation),
MAX(0.0, CGRectGetHeight(aRect) - 5.0));
}
/*
Returns the colour of the CSS selection view: the flat selection colour, with the
selection radius when there is one; or, in the source-list style, a linear gradient whose
first and last point are the top and bottom line colours.
*/
+ (CPColor)_CSSColorForSelection:(Object)aSelection
{
if (!aSelection.gradient)
{
if (!aSelection.radius)
return aSelection.color;
return [CPColor colorWithCSSDictionary:@{
@"background-color": aSelection.color,
@"border-radius": aSelection.radius + "px"
}];
}
var gradient = aSelection.gradient,
colors = gradient.colors,
locations = gradient.locations,
topLineColor = aSelection.topLineColor,
bottomLineColor = aSelection.bottomLineColor,
topInset = topLineColor ? 1.0 : 0.0,
bottomInset = bottomLineColor ? 1.0 : 0.0,
value = [@"linear-gradient(to bottom"];
if (topLineColor)
value.push(@", ", topLineColor, @" 0px, ", topLineColor, @" 1px");
for (var i = 0, count = colors.length; i < count; i++)
{
var location = locations ? locations[i] : i / MAX(1, count - 1),
offset = topInset - location * (topInset + bottomInset);
value.push(@", ", [CPTableRowView _colorFromCGColor:colors[i]], @" calc(" + (location * 100.0) + "% + " + offset + "px)");
}
if (bottomLineColor)
value.push(@", ", bottomLineColor, @" calc(100% - 1px), ", bottomLineColor, @" 100%");
value.push(@")");
return [CPColor colorWithCSSDictionary:@{ @"background-image": value }];
}
+ (CPColor)_colorFromCGColor:(CGColor)aColor
{
var components = aColor.components;
return [CPColor colorWithRed:components[0] green:components[1] blue:components[2] alpha:components[3]];
}
/*
The canvas renderer. Each method draws one part of aLook in aRect, a row rect, on the
current graphics context, and draws nothing for a part that is nil. A colour that CSS
defines has no canvas form and is not drawn.
*/
+ (void)_drawBackgroundOfLook:(Object)aLook inRect:(CGRect)aRect
{
var color = aLook.backgroundColor;
if (!color || [color isCSSBased])
return;
var context = [[CPGraphicsContext currentContext] graphicsPort];
CGContextSetFillColor(context, color);
CGContextFillRect(context, aRect);
}
+ (void)_drawSelectionOfLook:(Object)aLook inRect:(CGRect)aRect
{
var selection = aLook.selection;
if (!selection)
return;
var context = [[CPGraphicsContext currentContext] graphicsPort],
minX = CGRectGetMinX(aRect),
minY = CGRectGetMinY(aRect),
maxX = CGRectGetMaxX(aRect),
maxY = CGRectGetMaxY(aRect);
if (selection.gradient)
{
CGContextBeginPath(context);
CGContextAddRect(context, aRect);
CGContextDrawLinearGradient(context, selection.gradient, CGPointMake(minX, minY), CGPointMake(minX, maxY), 0);
if (selection.topLineColor && ![selection.topLineColor isCSSBased])
{
CGContextSetFillColor(context, selection.topLineColor);
CGContextFillRect(context, CGRectMake(minX, minY, maxX - minX, 1.0));
}
if (selection.bottomLineColor && ![selection.bottomLineColor isCSSBased])
{
CGContextSetFillColor(context, selection.bottomLineColor);
CGContextFillRect(context, CGRectMake(minX, maxY - 1.0, maxX - minX, 1.0));
}
}
else if (![selection.color isCSSBased])
{
CGContextSetFillColor(context, selection.color);
if (selection.radius > 0)
CGContextFillRoundedRectangleInRect(context, aRect, selection.radius, YES, YES, YES, YES);
else
CGContextFillRect(context, aRect);
}
var lineColor = aLook.selectionBottomLineColor;
if (lineColor && ![lineColor isCSSBased])
{
CGContextSetFillColor(context, lineColor);
CGContextFillRect(context, CGRectMake(minX, maxY - 1.0, maxX - minX, 1.0));
}
}
+ (void)_drawSeparatorOfLook:(Object)aLook inRect:(CGRect)aRect
{
var separator = aLook.separator;
if (!separator || [separator.color isCSSBased])
return;
var context = [[CPGraphicsContext currentContext] graphicsPort];
CGContextSetFillColor(context, separator.color);
CGContextFillRect(context, [self _separatorRectOfLook:separator inRect:aRect]);
}
+ (void)_drawDropFeedbackOfLook:(Object)aLook inRect:(CGRect)aRect
{
var drop = aLook.drop;
if (!drop)
return;
var context = [[CPGraphicsContext currentContext] graphicsPort],
rect = [self _dropFeedbackRectOfLook:drop inRect:aRect];
if (drop.backgroundColor && ![drop.backgroundColor isCSSBased])
{
CGContextSetFillColor(context, drop.backgroundColor);
CGContextFillRoundedRectangleInRect(context, rect, drop.borderRadius, YES, YES, YES, YES);
}
if (drop.borderColor && drop.borderWidth && ![drop.borderColor isCSSBased])
{
CGContextSetStrokeColor(context, drop.borderColor);
CGContextSetLineWidth(context, drop.borderWidth);
CGContextStrokeRoundedRectangleInRect(context, rect, drop.borderRadius, YES, YES, YES, YES);
}
}
@end
+4
View File
@@ -205,6 +205,10 @@
var rowIndexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [self numberOfRows])];
[self _layoutViewsForRowIndexes:rowIndexes columnIndexes:[CPIndexSet indexSetWithIndex:columnIndex]];
// The layout places the vertical grid lines and the column selection again.
[self setNeedsLayout];
[self _markDrawingPassForDisplay];
}
/*!
+14 -58
View File
@@ -107,6 +107,14 @@
[self _configureRowView:newRowView forRow:aRow];
}
/*
Blinks the feedback for a drop on the row of the current drop target.
*/
- (void)_blinkDropTargetRowView
{
[_visibleRowViews[_dropTargetRow] _blinkDraggingDestinationFeedback];
}
/*!
@ignore
*/
@@ -335,24 +343,25 @@
@end
/*
Draws the marker for a drop between rows, and the frame for a drop on the whole table
view. The row view of the row draws the feedback for a drop on a row.
*/
@implementation _CPDropOperationDrawingView : CPView
{
unsigned dropOperation @accessors;
CPTableView tableView @accessors;
int currentRow @accessors;
BOOL isBlinking @accessors;
}
- (void)drawRect:(CGRect)aRect
{
if (tableView._destinationDragStyle === CPTableViewDraggingDestinationFeedbackStyleNone || isBlinking)
if (tableView._destinationDragStyle === CPTableViewDraggingDestinationFeedbackStyleNone)
return;
var context = [[CPGraphicsContext currentContext] graphicsPort],
borderRadius,
borderColor,
borderWidth,
backgroundColor;
borderWidth;
if (currentRow === -1)
{
@@ -364,34 +373,6 @@
CGContextStrokeRect(context, [self bounds]);
}
else if (dropOperation === CPTableViewDropOn)
{
//if row is selected don't fill and stroke white
var selectedRows = [tableView selectedRowIndexes],
newRect = CGRectMake(aRect.origin.x + 2, aRect.origin.y + 2, aRect.size.width - 4, aRect.size.height - 5);
if ([selectedRows containsIndex:currentRow])
{
borderRadius = [tableView valueForThemeAttribute:@"dropview-on-selected-border-radius"];
borderColor = [tableView valueForThemeAttribute:@"dropview-on-selected-border-color"];
borderWidth = [tableView valueForThemeAttribute:@"dropview-on-selected-border-width"];
backgroundColor = [tableView valueForThemeAttribute:@"dropview-on-selected-background-color"];
}
else
{
borderRadius = [tableView valueForThemeAttribute:@"dropview-on-border-radius"];
borderColor = [tableView valueForThemeAttribute:@"dropview-on-border-color"];
borderWidth = [tableView valueForThemeAttribute:@"dropview-on-border-width"];
backgroundColor = [tableView valueForThemeAttribute:@"dropview-on-background-color"];
}
CGContextSetStrokeColor(context, borderColor);
CGContextSetLineWidth(context, borderWidth);
CGContextSetFillColor(context, backgroundColor);
CGContextFillRoundedRectangleInRect(context, newRect, borderRadius, YES, YES, YES, YES);
CGContextStrokeRoundedRectangleInRect(context, newRect, borderRadius, YES, YES, YES, YES);
}
else if (dropOperation === CPTableViewDropAbove)
{
//reposition the view up a tad
@@ -421,29 +402,4 @@
}
}
- (void)blink
{
if (dropOperation !== CPTableViewDropOn)
return;
isBlinking = YES;
var showCallback = function()
{
[self setHidden: NO];
isBlinking = NO;
};
var hideCallback = function()
{
[self setHidden: YES];
isBlinking = YES;
};
[self setHidden: YES];
[CPTimer scheduledTimerWithTimeInterval:0.1 callback:showCallback repeats:NO];
[CPTimer scheduledTimerWithTimeInterval:0.19 callback:hideCallback repeats:NO];
[CPTimer scheduledTimerWithTimeInterval:0.27 callback:showCallback repeats:NO];
}
@end
+544 -117
View File
@@ -22,73 +22,570 @@
@import "CPTableViewCore.j"
@class CPTableRowView
@class CPButton
@class CPClipView
@class CPUserDefaults
@class CPTableHeaderView
@class CPTableView
@class _CPTableColumnHeaderView
@class CPClipView
@class CPButton
@class _CPDropOperationDrawingView
/*
The names of the table view's two ephemeral subviews. CPView does not archive ephemeral
subviews.
The decoration view holds the views of the column selection and the vertical grid lines.
It lies in front of the row views and behind every other subview.
The drawing pass view is the canvas of the four old drawing methods. It exists only for a
class that overrides one of them, and lies in front of the decoration view and behind the
data views.
*/
var CPTableViewDecorationViewName = @"table-decoration",
CPTableViewDrawingPassViewName = @"table-drawing-pass";
/*
The layers of the drawing pass for each table view class, by class UID.
*/
var CPTableViewDrawingPassLayersForClasses = { };
/*
The canvas of the drawing pass. Its frame is the exposed rect of the table view.
*/
@implementation _CPTableDrawView : CPView
{
CPTableView _tableView;
}
- (id)initWithTableView:(CPTableView)aTableView
{
self = [super initWithFrame:CGRectMakeZero()];
if (self)
{
_tableView = aTableView;
[self setHitTests:NO];
}
return self;
}
- (void)drawRect:(CGRect)aRect
{
var frame = [self frame],
context = [[CPGraphicsContext currentContext] graphicsPort];
CGContextTranslateCTM(context, -CGRectGetMinX(frame), -CGRectGetMinY(frame));
[_tableView _drawRect:aRect];
}
@end
/*
Holds the views of the column selection, behind, and of the vertical grid lines, in
front. The table view keeps the views in two pools and places them in its layout.
*/
@implementation _CPTableDecorationView : CPView
{
CPArray _columnSelectionViews;
CPArray _gridLineViews;
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if (self)
{
_columnSelectionViews = [];
_gridLineViews = [];
[self setHitTests:NO];
}
return self;
}
- (void)setColumnSelectionRects:(CPArray)someRects color:(CPColor)aColor
{
[self _showRects:someRects color:aColor inViews:_columnSelectionViews atBack:YES];
}
- (void)setGridLineRects:(CPArray)someRects color:(CPColor)aColor
{
[self _showRects:someRects color:aColor inViews:_gridLineViews atBack:NO];
}
/*
Shows one view of someViews for each rect, made when the pool has too few, and hides the
others.
*/
- (void)_showRects:(CPArray)someRects color:(CPColor)aColor inViews:(CPArray)someViews atBack:(BOOL)atBack
{
var count = someRects.length;
while (someViews.length < count)
{
var newView = [[CPView alloc] initWithFrame:CGRectMakeZero()];
[newView setHitTests:NO];
if (atBack)
[self addSubview:newView positioned:CPWindowBelow relativeTo:nil];
else
[self addSubview:newView];
someViews.push(newView);
}
for (var i = 0; i < someViews.length; i++)
{
var view = someViews[i];
if (i < count)
{
[view setFrame:someRects[i]];
[view setBackgroundColor:aColor];
[view setHidden:NO];
}
else
[view setHidden:YES];
}
}
@end
@implementation CPTableView (Drawing)
// MARK: The drawing pass
- (void)_updateSelectedColumnBackgrounds
/*
Returns the layers that the drawing pass of the receiver draws. The pass draws a layer
when the class overrides the method of that layer or of a layer behind it, so a class that
overrides none of the four methods has no drawing pass. The result is found once for each
class, by comparison of the methods with CPTableView's.
*/
+ (unsigned)_drawingPassLayers
{
if (!CPDOMAvailable)
return;
var UID = [self UID],
layers = CPTableViewDrawingPassLayersForClasses[UID];
// 1. Remove existing column background views
[_selectedColumnBackgroundViews makeObjectsPerformSelector:@selector(removeFromSuperview)];
[_selectedColumnBackgroundViews removeAllObjects];
// 2. If no highlighting style, stop here
if ([self selectionHighlightStyle] === CPTableViewSelectionHighlightStyleNone)
return;
var color = [self _isFocused] ? [self selectionHighlightColor] : [self unfocusedSelectionHighlightColor],
bounds = [self bounds];
// 3. Create a view for each selected column index
[_selectedColumnIndexes enumerateIndexesUsingBlock:function(idx, stop)
if (layers === undefined)
{
var rect = [self rectOfColumn:idx];
// Ensure the highlight spans the full height of the table
rect.size.height = MAX(CGRectGetHeight(bounds), [self frame].size.height);
var overrides = function(aSelector)
{
return [self instanceMethodForSelector:aSelector] !== [CPTableView instanceMethodForSelector:aSelector];
},
rows = _CPTableViewDrawingLayerRows,
grid = rows | _CPTableViewDrawingLayerGrid,
selection = grid | _CPTableViewDrawingLayerSelection,
background = selection | _CPTableViewDrawingLayerBackground;
var view = [[CPView alloc] initWithFrame:rect];
[view setBackgroundColor:color];
[view setHitTests:NO];
if (overrides(@selector(drawBackgroundInClipRect:)))
layers = background;
else if (overrides(@selector(highlightSelectionInClipRect:)))
layers = selection;
else if (overrides(@selector(drawGridInClipRect:)))
layers = grid;
else if (overrides(@selector(drawRow:clipRect:)))
layers = rows;
else
layers = 0;
// Add to the table view at the bottom of the stack
[self addSubview:view positioned:CPWindowBelow relativeTo:nil];
[_selectedColumnBackgroundViews addObject:view];
}];
// 4. Z-Order Correction:
// Row views (alternating row colors) are also added "Below nil".
// To ensure the Column selection appears ON TOP of the row alternating colors,
// we must push the currently visible row views to the very back.
for (var rowIndex in _visibleRowViews)
{
if (_visibleRowViews.hasOwnProperty(rowIndex))
[self addSubview:_visibleRowViews[rowIndex] positioned:CPWindowBelow relativeTo:nil];
CPTableViewDrawingPassLayersForClasses[UID] = layers;
}
return layers;
}
- (unsigned)_drawingPassLayers
{
return [[self class] _drawingPassLayers];
}
/*
Draws the layers of the drawing pass: background, selection and grid, each once for the
exposed rect, then each row on screen, in ascending order.
*/
- (void)_drawRect:(CGRect)aRect
{
var exposedRect = [self exposedRect],
layers = [self _drawingPassLayers];
if (layers & _CPTableViewDrawingLayerBackground)
[self drawBackgroundInClipRect:exposedRect];
if (layers & _CPTableViewDrawingLayerSelection)
[self highlightSelectionInClipRect:exposedRect];
if (layers & _CPTableViewDrawingLayerGrid)
[self drawGridInClipRect:exposedRect];
if (layers & _CPTableViewDrawingLayerRows)
[self _drawRowsInClipRect:exposedRect];
}
/*
Calls drawRow:clipRect: for each row in aRect, in ascending order, with the part of the
row inside aRect.
*/
- (void)_drawRowsInClipRect:(CGRect)aRect
{
var rows = [self rowsInRect:aRect],
lastRow = MIN(CPMaxRange(rows), [self numberOfRows]);
for (var row = rows.location; row < lastRow; row++)
[self drawRow:row clipRect:CGRectIntersection(aRect, [self rectOfRow:row])];
}
/*
Returns the rect of aRow limited to the horizontal extent of aRect. The rows below the
last row have the default height.
*/
- (CGRect)_rectOfRow:(CPInteger)aRow inClipRect:(CGRect)aRect
{
var rowRect = [self _rectOfRow:aRow checkRange:NO];
return CGRectMake(CGRectGetMinX(aRect), CGRectGetMinY(rowRect), CGRectGetWidth(aRect), CGRectGetHeight(rowRect));
}
/*
Returns the state of aRow: the state of its row view, else the state that the table view
would give a row view.
*/
- (Object)_rowStateForRow:(CPInteger)aRow
{
var rowView = _visibleRowViews[aRow];
if (rowView)
return [rowView _rowState];
return [self _tableRowStateForRow:aRow];
}
- (Object)_lookForRow:(CPInteger)aRow
{
return [CPTableRowView _lookForTableView:self rowState:[self _rowStateForRow:aRow]];
}
/*!
@ignore
Draws the background of the rows in a given clip rect on the current graphics context:
the alternating row colours, the group row colour and the background colours that the
application set on row views. The rows below the last row are included.
A subclass overrides this method to draw something other than the standard background.
The table view then draws the background, the selection, the grid and the rows on a
canvas, and its row views draw none of these.
@note The table view calls this method. Do not call it directly to redraw; send
\c setNeedsDisplay: instead.
*/
- (void)drawBackgroundInClipRect:(CGRect)aRect
{
var rows = [self _exposedRowsInRect:aRect];
for (var row = rows.location; row < CPMaxRange(rows); row++)
[CPTableRowView _drawBackgroundOfLook:[self _lookForRow:row] inRect:[self _rectOfRow:row inClipRect:aRect]];
}
/*!
Draws the selection in a given clip rect on the current graphics context: the selected
rows in the selection highlight style, or the selected columns in the selection colour.
This method is kept for applications written for earlier versions of Cappuccino. New code
changes the look of the selection with a subclass of \c CPTableRowView. A subclass that
overrides this method draws the selection, the grid and the rows on a canvas.
@note The table view calls this method. Do not call it directly to redraw; send
\c setNeedsDisplay: instead.
*/
- (void)highlightSelectionInClipRect:(CGRect)aRect
{
if (_selectionHighlightStyle === CPTableViewSelectionHighlightStyleNone)
return;
var rows = [self _exposedRowsInRect:aRect],
lastRow = MIN(CPMaxRange(rows), [self numberOfRows]);
for (var row = rows.location; row < lastRow; row++)
{
if ([_selectedRowIndexes containsIndex:row])
[CPTableRowView _drawSelectionOfLook:[self _lookForRow:row] inRect:[self _rectOfRow:row inClipRect:aRect]];
}
var rects = [self _selectedColumnRectsInRect:aRect],
color = [self _columnSelectionColor];
if (!rects.length || !color || [color isCSSBased])
return;
var context = [[CPGraphicsContext currentContext] graphicsPort];
CGContextSetFillColor(context, color);
for (var i = 0; i < rects.length; i++)
CGContextFillRect(context, rects[i]);
}
/*!
Draws the grid in a given clip rect on the current graphics context, as the grid style
mask gives it: a horizontal line at the bottom edge of each row that is not a group row,
the rows below the last row included, and a vertical line at the right edge of each
column.
A subclass overrides this method to draw grid lines other than the standard ones. The
table view then draws the grid and the rows on a canvas.
@note The table view calls this method. Do not call it directly to redraw; send
\c setNeedsDisplay: instead.
*/
- (void)drawGridInClipRect:(CGRect)aRect
{
if (_gridStyleMask & CPTableViewSolidHorizontalGridLineMask)
{
var rows = [self _exposedRowsInRect:aRect];
for (var row = rows.location; row < CPMaxRange(rows); row++)
[CPTableRowView _drawSeparatorOfLook:[self _lookForRow:row] inRect:[self _rectOfRow:row inClipRect:aRect]];
}
var rects = [self _verticalGridLineRectsInRect:aRect],
color = [self gridColor];
if (!rects.length || !color || [color isCSSBased])
return;
var context = [[CPGraphicsContext currentContext] graphicsPort];
CGContextSetFillColor(context, color);
for (var i = 0; i < rects.length; i++)
CGContextFillRect(context, rects[i]);
}
/*!
Draws over a row. The default implementation draws nothing. A subclass overrides this
method to draw content over a row, for example a badge in a source list. The table view
calls it for each row on screen, in ascending order, after the background, the selection
and the grid, with the part of the row inside the visible area.
This method is kept for applications written for earlier versions of Cappuccino. New code
draws in a subclass of \c CPTableRowView, or adds views to the row.
@note \c tableView:willDisplayView:forTableColumn:row: is sent to the delegate before
drawing.
*/
- (void)drawRow:(CPInteger)row clipRect:(CGRect)rect
{
}
// MARK: Views of the table view
/*
Returns the rects of the selected columns in aRect, over the full height of aRect.
*/
- (CPArray)_selectedColumnRectsInRect:(CGRect)aRect
{
var rects = [];
if (_selectionHighlightStyle === CPTableViewSelectionHighlightStyleNone || ![_selectedColumnIndexes count])
return rects;
[[self columnIndexesInRect:aRect] enumerateIndexesUsingBlock:function(column, stop)
{
if (![_selectedColumnIndexes containsIndex:column])
return;
var columnRect = [self rectOfColumn:column];
rects.push(CGRectMake(CGRectGetMinX(columnRect), CGRectGetMinY(aRect), CGRectGetWidth(columnRect), CGRectGetHeight(aRect)));
}];
return rects;
}
/*
Returns the rects of the vertical grid lines in aRect, one at the right edge of each
column, over the full height of aRect.
*/
- (CPArray)_verticalGridLineRectsInRect:(CGRect)aRect
{
var rects = [];
if (!(_gridStyleMask & CPTableViewSolidVerticalGridLineMask))
return rects;
var thickness = [self currentValueForThemeAttribute:@"grid-line-thickness"] || 1.0;
[[self columnIndexesInRect:aRect] enumerateIndexesUsingBlock:function(column, stop)
{
var columnRect = [self rectOfColumn:column];
rects.push(CGRectMake(CGRectGetMaxX(columnRect) - thickness, CGRectGetMinY(aRect), thickness, CGRectGetHeight(aRect)));
}];
return rects;
}
/*
The column selection has the flat selection colour, or its unfocused variant.
*/
- (CPColor)_columnSelectionColor
{
return [self _isFocused] ? [self selectionHighlightColor] : [self unfocusedSelectionHighlightColor];
}
- (CGRect)rectForEphemeralSubviewNamed:(CPString)aViewName
{
/*
The decoration view keeps the frame that -_layoutTableDecorationViews gives it: the
bounds of the table view while it shows a view, else an empty rect.
*/
if (aViewName === CPTableViewDecorationViewName)
{
var decorationView = [self ephemeralSubviewNamed:CPTableViewDecorationViewName];
return decorationView ? [decorationView frame] : CGRectMakeZero();
}
if (aViewName === CPTableViewDrawingPassViewName)
return [self _drawingPassLayers] ? [self exposedRect] : nil;
return [super rectForEphemeralSubviewNamed:aViewName];
}
- (CPView)createEphemeralSubviewNamed:(CPString)aViewName
{
if (aViewName === CPTableViewDecorationViewName)
return [[_CPTableDecorationView alloc] initWithFrame:CGRectMakeZero()];
if (aViewName === CPTableViewDrawingPassViewName)
return [[_CPTableDrawView alloc] initWithTableView:self];
return [super createEphemeralSubviewNamed:aViewName];
}
/*
Makes and places the decoration view and the drawing pass view. The table view calls this
method at the start of each load, so that both views exist before the first row view: row
views are added behind every other subview, so they lie behind both.
*/
- (void)_layoutTableDrawingViews
{
[self layoutEphemeralSubviewNamed:CPTableViewDecorationViewName
positioned:CPWindowBelow
relativeToEphemeralSubviewNamed:nil];
[self layoutEphemeralSubviewNamed:CPTableViewDrawingPassViewName
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:CPTableViewDecorationViewName];
}
- (_CPTableDrawView)_drawingPassView
{
return [self ephemeralSubviewNamed:CPTableViewDrawingPassViewName];
}
/*
Marks the canvas of the drawing pass for display, when there is one.
*/
- (void)_markDrawingPassForDisplay
{
[[self _drawingPassView] setNeedsDisplay:YES];
}
/*
Places the views of the column selection and the vertical grid lines, over the full
height of the table view, for the columns in the exposed rect. A layer that the drawing
pass draws has no views.
The column selection views were made again from the first responder handlers, twice
through a timer, because the focus was not yet current when a handler ran. The layout runs
after the event, when the focus is current.
*/
- (void)_layoutTableDecorationViews
{
var decorationView = [self ephemeralSubviewNamed:CPTableViewDecorationViewName];
if (!decorationView)
return;
var passLayers = [self _drawingPassLayers],
exposedRect = [self exposedRect],
rect = CGRectMake(CGRectGetMinX(exposedRect), 0.0, CGRectGetWidth(exposedRect), CGRectGetHeight([self bounds])),
selectionRects = (passLayers & _CPTableViewDrawingLayerSelection) ? [] : [self _selectedColumnRectsInRect:rect],
gridLineRects = (passLayers & _CPTableViewDrawingLayerGrid) ? [] : [self _verticalGridLineRectsInRect:rect];
/*
The decoration view spanned the table view at all times, so a table view without column
selection or vertical grid lines had an empty view over its full height. It now has the
bounds of the table view only while it shows a view.
*/
[decorationView setFrame:(selectionRects.length || gridLineRects.length) ? [self bounds] : CGRectMakeZero()];
[decorationView setColumnSelectionRects:selectionRects color:[self _columnSelectionColor]];
[decorationView setGridLineRects:gridLineRects color:[self gridColor]];
}
// MARK: Keeping the visible rows current
/*!
Marks the table view for display. With \c YES this is the signal that the look of the
table view changed: the visible row views take the state of the table view again and lay
out, the views of the column selection and the grid lines are placed again, and the canvas
of a subclass that overrides a drawing method draws again.
A change of theme, theme state, appearance or theme attribute sends this signal. An
application sends it after a change that the table view cannot see, such as new content
that \c drawRow:clipRect: draws.
*/
- (void)setNeedsDisplay:(BOOL)aFlag
{
[super setNeedsDisplay:aFlag];
[[self headerView] setNeedsDisplay:YES];
// CPView sends the signal during initialization, before the table view has row views.
if (!aFlag || !_visibleRowViews)
return;
_unfocusedSelectionHighlightColor = nil;
_unfocusedSourceListSelectionColor = nil;
/*
The row views take the state now, so that their properties are current at once, and
again in the layout, when the focus is current after an event.
*/
for (var key in _visibleRowViews)
{
if (!_visibleRowViews.hasOwnProperty(key))
continue;
var rowView = _visibleRowViews[key];
[self _configureRowView:rowView forRow:+key];
[rowView setNeedsLayout];
[rowView setNeedsDisplay:YES];
}
_rowViewsNeedConfiguration = YES;
[self _markDrawingPassForDisplay];
[self setNeedsLayout];
}
/*
Gives every visible row view the state of the table view again, after the signal of
-setNeedsDisplay:.
*/
- (void)_configureRowViewsAfterLookChangeIfNeeded
{
if (!_rowViewsNeedConfiguration)
return;
_rowViewsNeedConfiguration = NO;
for (var key in _visibleRowViews)
{
if (_visibleRowViews.hasOwnProperty(key))
[self _configureRowView:_visibleRowViews[key] forRow:+key];
}
}
/*!
@@ -108,74 +605,4 @@
return [[self window] isKeyWindow] && ([[self window] firstResponder] === self || _editingRow !== CPNotFound);
}
/*!
@ignore
*/
- (void)_drawRect:(CGRect)aRect
{
// NO-OP: We no longer draw on canvas. DOM composition handles background, grid and selection.
if (_implementsCustomDrawRow)
[self _drawRows:_exposedRows clipRect:aRect];
}
/*!
Draws the background in a given clip rect.
Deprecated: Handled by CPTableRowView
*/
- (void)drawBackgroundInClipRect:(CGRect)aRect
{
}
/*!
Draws the grid for the tableview.
Deprecated: Handled by CPTableRowView
*/
- (void)drawGridInClipRect:(CGRect)aRect
{
}
/*!
Draws the selection.
Deprecated: Handled by CPTableRowView
*/
- (void)highlightSelectionInClipRect:(CGRect)aRect
{
}
/*!
@ignore
Draws the group rows
FIX ME: this should be themed...
*/
- (void)_drawGroupRowsForRects:(CPArray)rects
{
// TODO: Implement Group Row styling in CPTableRowView
}
/*!
@ignore
*/
- (void)_drawRows:(CPIndexSet)rowsIndexes clipRect:(CGRect)clipRect
{
var row = [rowsIndexes firstIndex];
while (row !== CPNotFound)
{
[self drawRow:row clipRect:CGRectIntersection(clipRect, [self rectOfRow:row])];
row = [rowsIndexes indexGreaterThanIndex:row];
}
}
/*!
While this method doesn't do anything in Cappuccino, subclasses can override it to customize the
appearance of a row.
@note \c tableView:willDisplayView:forTableColumn:row is sent to the delegate before drawing
*/
- (void)drawRow:(CPInteger)row clipRect:(CGRect)rect
{
// This method does currently nothing in cappuccino. Can be overridden by subclasses.
}
@end
+1 -2
View File
@@ -566,9 +566,8 @@
[self setFrameSize:CGSizeMake(width, height)];
[self _updateSelectedColumnBackgrounds];
[self setNeedsLayout];
[self _markDrawingPassForDisplay];
}
+8 -16
View File
@@ -205,6 +205,9 @@
else
[self _notifyViewDidBecomeFirstResponder];
// The start and the end of editing change the focus of the table view.
[self setNeedsDisplay:YES];
// This is for cell-based tables only. In view-based mode, we do not change the textfield apprearence during an edit.
if (!_isViewBased && _editingRow !== CPNotFound && [responder isKindOfClass:[CPTextField class]] && [responder isEditable] && [responder superview] == self)
{
@@ -242,30 +245,19 @@
[self _resignFirstResponderWithoutSendingAction:textField];
}
/*
The row views and the column selection follow the focus through the signal of
-setNeedsDisplay:, which a change of key window, first responder or editing sends. These
methods update the data views.
*/
- (void)_notifyViewDidBecomeFirstResponder
{
// Ensure the row highlights turn "blue" (active)
[self _updateAllVisibleRowViews];
// Ensure the text turns white
[self _updateDataViewsFocusState];
// for symmetry with _notifyViewDidResignFirstResponder
setTimeout(function() {
[self _updateSelectedColumnBackgrounds];
}, 0);
}
- (void)_notifyViewDidResignFirstResponder
{
// Ensure the row highlights turn "gray" (inactive)
[self _updateAllVisibleRowViews];
// Ensure the text turns black
[self _updateDataViewsFocusState];
// needed because _isFocussed still returns true in this iteration of the run loop
setTimeout(function() {
[self _updateSelectedColumnBackgrounds];
}, 0);
}
@end
+5 -3
View File
@@ -66,7 +66,6 @@
_selectedColumnIndexes = [columns copy];
[self _updateHighlightWithOldColumns:previousSelectedIndexes newColumns:_selectedColumnIndexes];
[self _updateSelectedColumnBackgrounds];
if (_headerView)
[_headerView setNeedsDisplay:YES];
@@ -114,8 +113,6 @@
[self _updateHighlightWithOldColumns:_selectedColumnIndexes newColumns:[CPIndexSet indexSet]];
_selectedColumnIndexes = [CPIndexSet indexSet];
[self _updateSelectedColumnBackgrounds];
if (_headerView)
[_headerView setNeedsDisplay:YES];
}
@@ -175,6 +172,7 @@
[self _enumerateViewsInRows:newRows columns:_exposedColumns usingBlock:_BlockSelectView];
[self _configureRowViewsForSelectionChangeFromRows:oldRows toRows:newRows];
[self _markDrawingPassForDisplay];
}
/*!
@@ -202,6 +200,10 @@
[headerView setThemeState:CPThemeStateSelected];
}];
}
// The layout places the column selection views.
[self setNeedsLayout];
[self _markDrawingPassForDisplay];
}
/*!
+60 -39
View File
@@ -44,6 +44,21 @@
*/
- (void)load
{
/*
The canvas of the drawing pass draws again when the rows, the columns or the exposed
rect change. A load that changes none of them does not mark it.
*/
var drawingPassView = [self _drawingPassView],
previousDrawingPassFrame = drawingPassView ? CGRectMakeCopy([drawingPassView frame]) : nil,
drawingPassNeedsDisplay = _reloadAllRows;
[self _layoutTableDrawingViews];
drawingPassView = [self _drawingPassView];
if (drawingPassView && (!previousDrawingPassFrame || !CGRectEqualToRect(previousDrawingPassFrame, [drawingPassView frame])))
drawingPassNeedsDisplay = YES;
if (_reloadAllRows)
{
[self _removeAllRowViews];
@@ -92,10 +107,11 @@
[self _announceRowViewsInRows:addedRowViewRows];
// Remove old draw view call
// [_tableDrawView setFrame:exposedRect];
if ([newlyExposedRows count] || [obscuredRows count] || [newlyExposedColumns count] || [obscuredColumns count])
drawingPassNeedsDisplay = YES;
// [self setNeedsDisplay:YES]; // Not needed for structure changes
if (drawingPassNeedsDisplay)
[drawingPassView setNeedsDisplay:YES];
// if we have any columns to remove do that here
@@ -415,18 +431,20 @@
}
/*
Sets every property of aRowView from the state of the table view for aRow. A row view
only shows this state.
Returns the state that the table view gives the row view of aRow, in the form of
-[CPTableRowView _rowState]. The default background is the group row colour for a group
row outside the source-list style, else the alternating colour of the row when the table
view uses alternating colours, else none.
*/
- (void)_configureRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow
- (Object)_tableRowStateForRow:(CPInteger)aRow
{
var isFillerRow = aRow >= [self numberOfRows],
isGroupRow = !isFillerRow && [self _sendDelegateIsGroupRow:aRow],
defaultColor = nil;
if (isGroupRow)
defaultColor = [self valueForThemeAttribute:@"group-row-background-color"];
else if (_usesAlternatingRowBackgroundColors)
if (isGroupRow && _selectionHighlightStyle !== CPTableViewSelectionHighlightStyleSourceList)
defaultColor = [self currentValueForThemeAttribute:@"group-row-background-color"];
else if (!isGroupRow && _usesAlternatingRowBackgroundColors)
{
var colors = [self alternatingRowBackgroundColors],
count = [colors count];
@@ -435,17 +453,40 @@
defaultColor = colors[aRow % count];
}
return {
selected: !isFillerRow && [self isRowSelected:aRow],
emphasized: [self _isFocused],
groupRowStyle: isGroupRow,
selectionHighlightStyle: _selectionHighlightStyle,
previousRowSelected: aRow > 0 && [self isRowSelected:aRow - 1],
nextRowSelected: [self isRowSelected:aRow + 1],
targetForDropOperation: aRow === _dropTargetRow,
draggingDestinationFeedbackStyle: _destinationDragStyle,
indentationForDropOperation: isFillerRow ? 0.0 : [self _indentationForDropOperationOnRow:aRow],
backgroundColor: nil,
defaultBackgroundColor: defaultColor
};
}
/*
Sets every property of aRowView from the state of the table view for aRow. A row view
only shows this state.
*/
- (void)_configureRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow
{
var state = [self _tableRowStateForRow:aRow];
[aRowView _setTableView:self];
[aRowView _setDefaultBackgroundColor:defaultColor];
[aRowView setSelected:!isFillerRow && [self isRowSelected:aRow]];
[aRowView setEmphasized:[self _isFocused]];
[aRowView setGroupRowStyle:isGroupRow];
[aRowView setSelectionHighlightStyle:_selectionHighlightStyle];
[aRowView setPreviousRowSelected:aRow > 0 && [self isRowSelected:aRow - 1]];
[aRowView setNextRowSelected:[self isRowSelected:aRow + 1]];
[aRowView setDraggingDestinationFeedbackStyle:_destinationDragStyle];
[aRowView setTargetForDropOperation:aRow === _dropTargetRow];
[aRowView setIndentationForDropOperation:isFillerRow ? 0.0 : [self _indentationForDropOperationOnRow:aRow]];
[aRowView _setDefaultBackgroundColor:state.defaultBackgroundColor];
[aRowView setSelected:state.selected];
[aRowView setEmphasized:state.emphasized];
[aRowView setGroupRowStyle:state.groupRowStyle];
[aRowView setSelectionHighlightStyle:state.selectionHighlightStyle];
[aRowView setPreviousRowSelected:state.previousRowSelected];
[aRowView setNextRowSelected:state.nextRowSelected];
[aRowView setDraggingDestinationFeedbackStyle:state.draggingDestinationFeedbackStyle];
[aRowView setTargetForDropOperation:state.targetForDropOperation];
[aRowView setIndentationForDropOperation:state.indentationForDropOperation];
}
/*
@@ -471,24 +512,6 @@
}
}
/*
Configures every visible row view and marks it for layout. A change of the grid or of a
table view colour changes no property of a row view, but changes its look.
*/
- (void)_updateAllVisibleRowViews
{
for (var key in _visibleRowViews)
{
if (!_visibleRowViews.hasOwnProperty(key))
continue;
var rowView = _visibleRowViews[key];
[self _configureRowView:rowView forRow:+key];
[rowView setNeedsLayout];
}
}
- (void)_updateAllVisibleRowViewsFrames
{
for (var key in _visibleRowViews)
@@ -656,8 +679,6 @@
[_groupRows removeIndexesInRange:CPMakeRange(row, 1)];
[dataView unsetThemeState:CPThemeStateGroupRow];
}
[self setNeedsDisplay:YES];
}
if (!_isViewBased)
+26 -15
View File
@@ -117,6 +117,16 @@ CPTableViewGridNone = 0;
CPTableViewSolidVerticalGridLineMask = 1 << 0;
CPTableViewSolidHorizontalGridLineMask = 1 << 1;
/*
The layers of the drawing pass, back to front. A table view subclass that overrides the
method of a layer draws that layer and each layer in front of it on a canvas; the row
views and the table view's own views stop drawing those layers. Private.
*/
_CPTableViewDrawingLayerBackground = 1 << 0;
_CPTableViewDrawingLayerSelection = 1 << 1;
_CPTableViewDrawingLayerGrid = 1 << 2;
_CPTableViewDrawingLayerRows = 1 << 3;
CPTableViewNoColumnAutoresizing = 0;
CPTableViewUniformColumnAutoresizingStyle = 1; // FIX ME: This is FUBAR
CPTableViewSequentialColumnAutoresizingStyle = 2;
@@ -242,6 +252,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
BOOL _usesDefaultBackgroundColor;
unsigned _selectionHighlightStyle;
BOOL _rowViewsNeedConfiguration;
CPColor _unfocusedSelectionHighlightColor;
CPDictionary _unfocusedSourceListSelectionColor;
CPTableColumn _currentHighlightedTableColumn;
@@ -293,7 +304,6 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
BOOL _disableAutomaticResizing @accessors(property=disableAutomaticResizing);
BOOL _lastColumnShouldSnap;
BOOL _implementsCustomDrawRow;
BOOL _isViewBased;
BOOL _contentBindingExplicitlySet;
@@ -303,7 +313,6 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
BOOL _draggedColumnIsSelected;
BOOL _needsDifferedTableColumnRemove;
CPArray _differedColumnDataToRemove;
CPArray _selectedColumnBackgroundViews;
Function _BlockDeselectView;
Function _BlockSelectView;
@@ -463,7 +472,6 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
_sourceListInactiveBottomLineColor = [CPColor colorWithCalibratedRed:(150.0/255.0) green:(161.0/255.0) blue:(183.0/255.0) alpha:1.0];*/
_differedColumnDataToRemove = [];
_needsDifferedTableColumnRemove = NO;
_implementsCustomDrawRow = [self implementsSelector:@selector(drawRow:clipRect:)];
if (!_sortDescriptors)
_sortDescriptors = [];
@@ -525,8 +533,6 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
- (void)_initSubclass
{
_selectedColumnBackgroundViews = [];
_BlockDeselectView = function(view, row, column)
{
[view unsetThemeState:CPThemeStateSelectedDataView];
@@ -708,8 +714,6 @@ NOT YET IMPLEMENTED
{
[self _setupReload];
[self setNeedsLayout];
// No more manual draw rect
// [self setNeedsDisplay:YES];
}
// Reloads the views AND the data
@@ -894,6 +898,7 @@ NOT YET IMPLEMENTED
_rowHeight = MAX(0.0, aRowHeight);
[self setNeedsLayout];
[self _markDrawingPassForDisplay];
}
/*!
@@ -911,8 +916,13 @@ NOT YET IMPLEMENTED
*/
- (void)setUsesAlternatingRowBackgroundColors:(BOOL)shouldUseAlternatingRowBackgroundColors
{
shouldUseAlternatingRowBackgroundColors = !!shouldUseAlternatingRowBackgroundColors;
if (_usesAlternatingRowBackgroundColors === shouldUseAlternatingRowBackgroundColors)
return;
_usesAlternatingRowBackgroundColors = shouldUseAlternatingRowBackgroundColors;
[self _updateAllVisibleRowViews];
[self setNeedsDisplay:YES];
}
/*!
@@ -931,7 +941,6 @@ NOT YET IMPLEMENTED
- (void)setAlternatingRowBackgroundColors:(CPArray)alternatingRowBackgroundColors
{
[self setValue:alternatingRowBackgroundColors forThemeAttribute:@"alternating-row-colors"];
[self _updateAllVisibleRowViews];
}
/*!
@@ -990,7 +999,7 @@ NOT YET IMPLEMENTED
[self _updateHighlightWithOldRows:[CPIndexSet indexSet] newRows:_selectedRowIndexes];
[self _updateHighlightWithOldColumns:[CPIndexSet indexSet] newColumns:_selectedColumnIndexes];
[self _updateAllVisibleRowViews];
[self setNeedsDisplay:YES];
}
/*!
@@ -1004,7 +1013,6 @@ NOT YET IMPLEMENTED
return;
[self setValue:aColor forThemeAttribute:@"selection-color"];
[self _updateAllVisibleRowViews];
}
/*!
@@ -1127,7 +1135,6 @@ NOT YET IMPLEMENTED
- (void)setGridColor:(CPColor)aColor
{
[self setValue:aColor forThemeAttribute:@"grid-color"];
[self _updateAllVisibleRowViews];
}
/*!
@@ -1149,7 +1156,7 @@ NOT YET IMPLEMENTED
return;
_gridStyleMask = aGrideStyleMask;
[self _updateAllVisibleRowViews];
[self setNeedsDisplay:YES];
}
/*!
@@ -2071,6 +2078,8 @@ Your delegate can implement this method to avoid subclassing the tableview to ad
{
[self _updateDefaultBackgroundColor];
[self load];
[self _configureRowViewsAfterLookChangeIfNeeded];
[self _layoutTableDecorationViews];
}
/*!
@@ -2098,8 +2107,10 @@ Your delegate can implement this method to avoid subclassing the tableview to ad
{
_exposedRect = nil;
// No need to setNeedsDisplay for canvas
// [self setNeedsDisplay:YES];
/*
A scroll changes no look. The layout attaches row views to the rows that enter and
marks the canvas of the drawing pass, when there is one.
*/
[self setNeedsLayout];
}
+13 -2
View File
@@ -361,6 +361,18 @@ function _CPViewResolvedColorsAreSame(aColor, anotherColor)
};
}
/*
Returns YES when the instances of the receiver draw in drawRect:, so that they take display
marks. By default a class draws when it or a superclass below CPView implements drawRect:
or viewWillDraw. A class whose drawRect: draws only for some of its subclasses overrides
this method.
*/
+ (BOOL)_hasCustomDrawRect
{
return [self instanceMethodForSelector:@selector(drawRect:)] !== [CPView instanceMethodForSelector:@selector(drawRect:)]
|| [self instanceMethodForSelector:@selector(viewWillDraw)] !== [CPView instanceMethodForSelector:@selector(viewWillDraw)];
}
- (void)_setupViewFlags
{
var theClass = [self class],
@@ -370,8 +382,7 @@ function _CPViewResolvedColorsAreSame(aColor, anotherColor)
{
var flags = 0;
if ([theClass instanceMethodForSelector:@selector(drawRect:)] !== [CPView instanceMethodForSelector:@selector(drawRect:)]
|| [theClass instanceMethodForSelector:@selector(viewWillDraw)] !== [CPView instanceMethodForSelector:@selector(viewWillDraw)])
if ([theClass _hasCustomDrawRect])
flags |= CPViewHasCustomDrawRect;
if ([theClass instanceMethodForSelector:@selector(viewWillLayout)] !== [CPView instanceMethodForSelector:@selector(viewWillLayout)])
+6
View File
@@ -2142,6 +2142,12 @@ function ButtonBarImageAction()
[@"alternating-row-colors", alternatingRowColors],
[@"grid-color", gridColor],
[@"highlighted-grid-color", [CPColor whiteColor]],
/*
The table view drew group rows with a fixed grey gradient from 220 to 199 in its
code. The group row colour is now theme data; this is the middle of that
gradient.
*/
[@"group-row-background-color", [CPColor colorWithCalibratedWhite:210.0 / 255.0 alpha:1.0]],
[@"selection-color", selectionColor],
[@"sourcelist-selection-color", sourceListSelectionColor],
[@"sort-image", sortImage],
+464
View File
@@ -0,0 +1,464 @@
/*
* CPTableViewDrawingPassTest.j
* AppKit
*
* Created by David Richardson on 2026-11-17.
* Copyright David Richardson 2026.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <AppKit/AppKit.j>
/*
A table view draws its standard look with views: each row view draws its row, and the
table view draws the column selection and the vertical grid lines. A subclass that
overrides one of the four old drawing methods gets a canvas: the table view calls the
overridden method and the methods of the layers in front of it, background, selection,
grid, rows, once for each display, and the views stop drawing those layers.
A row view subclass that overrides a draw method draws on a canvas too, with AppKit's
order and conditions.
Unit tests run without a DOM, so these tests observe which methods run and which views
show, not what they draw.
*/
var DrawingPassRecord = nil;
@implementation DrawingPassBackgroundTableView : CPTableView
- (void)drawBackgroundInClipRect:(CGRect)aRect
{
DrawingPassRecord.push(@"background");
}
@end
@implementation DrawingPassSelectionTableView : CPTableView
- (void)highlightSelectionInClipRect:(CGRect)aRect
{
DrawingPassRecord.push(@"selection");
}
@end
@implementation DrawingPassGridTableView : CPTableView
- (void)drawGridInClipRect:(CGRect)aRect
{
DrawingPassRecord.push(@"grid");
}
@end
@implementation DrawingPassRowTableView : CPTableView
- (void)drawRow:(CPInteger)aRow clipRect:(CGRect)aRect
{
DrawingPassRecord.push(@"row " + aRow);
}
@end
/*
Records the calls of the four draw methods, in place of drawing.
*/
@implementation DrawingPassRecordingRowView : CPTableRowView
- (void)drawBackgroundInRect:(CGRect)aRect
{
DrawingPassRecord.push(@"background");
}
- (void)drawSelectionInRect:(CGRect)aRect
{
DrawingPassRecord.push(@"selection");
}
- (void)drawSeparatorInRect:(CGRect)aRect
{
DrawingPassRecord.push(@"separator");
}
- (void)drawDraggingDestinationFeedbackInRect:(CGRect)aRect
{
DrawingPassRecord.push(@"drop");
}
@end
/*
Overrides one draw method. The other three draw the standard look.
*/
@implementation DrawingPassSeparatorRowView : CPTableRowView
- (void)drawSeparatorInRect:(CGRect)aRect
{
DrawingPassRecord.push(@"separator");
}
@end
@implementation CPTableViewDrawingPassTest : OJTestCase
{
CPWindow theWindow;
CPTableView tableView;
}
- (void)setUp
{
// This will init the global var CPApp which are used internally in the AppKit
[[CPApplication alloc] init];
theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 400.0, 400.0) styleMask:CPWindowNotSizable];
DrawingPassRecord = [];
[self useTableViewOfClass:[CPTableView class]];
}
/*
Replaces the table view with one of aClass: 200 points square, with two columns and three
rows, laid out.
*/
- (void)useTableViewOfClass:(Class)aClass
{
[tableView removeFromSuperview];
tableView = [[aClass alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 200.0)];
var first = [[CPTableColumn alloc] initWithIdentifier:@"First"],
second = [[CPTableColumn alloc] initWithIdentifier:@"Second"];
[first setWidth:80.0];
[second setWidth:80.0];
[tableView addTableColumn:first];
[tableView addTableColumn:second];
[tableView setDataSource:self];
[[theWindow contentView] addSubview:tableView];
[tableView reloadData];
[self settle];
}
- (int)numberOfRowsInTableView:(CPTableView)aTableView
{
return 3;
}
- (id)tableView:(CPTableView)aTableView objectValueForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRow
{
return @"Value";
}
/*
Brings the table view to rest, as the end of a display cycle does: the table view and its
row views are laid out, nothing is marked for display, and nothing is recorded.
*/
- (void)settle
{
[tableView layoutIfNeeded];
[[tableView subviews] makeObjectsPerformSelector:@selector(layoutIfNeeded)];
[self drawMarkedViews];
DrawingPassRecord = [];
}
/*
The subviews of the table view that are not controls. Data views draw themselves and need
a canvas to do so.
*/
- (CPArray)tableSubviews
{
return [tableView subviews].filter(function(aView)
{
return ![aView isKindOfClass:[CPControl class]];
});
}
/*
CPView does not draw without a DOM, so the display cycle cannot reach drawRect: here. This
sends drawRect: to each subview that is marked for display, then displays it, which clears
the mark. The graphics port has no backing store.
*/
- (void)drawMarkedViews
{
var graphicsPort = { path: NULL, gState: CGGStateCreate(), gStateStack: [] };
[CPGraphicsContext setCurrentContext:[CPGraphicsContext graphicsContextWithGraphicsPort:graphicsPort flipped:YES]];
[self tableSubviews].forEach(function(aView)
{
if (![aView needsDisplay])
return;
[aView drawRect:[aView bounds]];
[aView displayIfNeeded];
});
}
- (CPView)canvasView
{
var subviews = [tableView subviews];
for (var i = 0; i < [subviews count]; i++)
if ([subviews[i] isKindOfClass:[_CPTableDrawView class]])
return subviews[i];
return nil;
}
- (CPArray)visibleGridLineViews
{
var decorationView = nil,
subviews = [tableView subviews];
for (var i = 0; i < [subviews count]; i++)
if ([subviews[i] isKindOfClass:[_CPTableDecorationView class]])
decorationView = subviews[i];
return [decorationView subviews].filter(function(aView)
{
return ![aView isHidden] && CGRectGetWidth([aView frame]) < CGRectGetHeight([aView frame]);
});
}
// MARK: The drawing pass
- (void)testATableViewWithoutAnOverrideHasNoCanvas
{
[self assertNull:[self canvasView]];
}
- (void)testATableViewWithoutAnOverrideMarksNothingForDisplay
{
[tableView selectRowIndexes:[CPIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
[tableView setGridStyleMask:CPTableViewSolidHorizontalGridLineMask];
[tableView layoutIfNeeded];
[self tableSubviews].forEach(function(aView)
{
[self assertFalse:[aView needsDisplay] message:[aView className] + " is marked for display"];
});
}
- (void)testAnOverrideOfTheBackgroundCallsEveryLayer
{
[self useTableViewOfClass:[DrawingPassBackgroundTableView class]];
[tableView setNeedsDisplay:YES];
[self drawMarkedViews];
[self assert:[@"background"] equals:DrawingPassRecord];
[self assert:15 equals:[DrawingPassBackgroundTableView _drawingPassLayers] message:@"background, selection, grid and rows"];
}
- (void)testAnOverrideOfTheSelectionCallsTheSelectionGridAndRows
{
[self useTableViewOfClass:[DrawingPassSelectionTableView class]];
[tableView setNeedsDisplay:YES];
[self drawMarkedViews];
[self assert:[@"selection"] equals:DrawingPassRecord];
[self assert:14 equals:[DrawingPassSelectionTableView _drawingPassLayers] message:@"selection, grid and rows"];
}
- (void)testAnOverrideOfTheGridCallsTheGridAndRows
{
[self useTableViewOfClass:[DrawingPassGridTableView class]];
[tableView setNeedsDisplay:YES];
[self drawMarkedViews];
[self assert:[@"grid"] equals:DrawingPassRecord];
[self assert:12 equals:[DrawingPassGridTableView _drawingPassLayers] message:@"grid and rows"];
}
- (void)testAnOverrideOfDrawRowCallsTheRowsOnly
{
[self useTableViewOfClass:[DrawingPassRowTableView class]];
[tableView setNeedsDisplay:YES];
[self drawMarkedViews];
[self assert:[@"row 0", @"row 1", @"row 2"] equals:DrawingPassRecord];
[self assert:8 equals:[DrawingPassRowTableView _drawingPassLayers] message:@"rows"];
}
/*
The canvas lies in front of the row views, so a layer that the canvas does not draw stays
with the views. An override of drawRow:clipRect: keeps the vertical grid lines as views;
an override of the grid draws them on the canvas.
*/
- (void)testAnOverrideOfDrawRowKeepsTheGridLinesAsViews
{
[self useTableViewOfClass:[DrawingPassRowTableView class]];
[tableView setGridStyleMask:CPTableViewSolidVerticalGridLineMask];
[tableView setGridColor:[CPColor redColor]];
[tableView layoutIfNeeded];
[self assert:2 equals:[[self visibleGridLineViews] count]];
}
- (void)testAnOverrideOfTheGridDrawsTheGridLinesOnTheCanvas
{
[self useTableViewOfClass:[DrawingPassGridTableView class]];
[tableView setGridStyleMask:CPTableViewSolidVerticalGridLineMask];
[tableView setGridColor:[CPColor redColor]];
[tableView layoutIfNeeded];
[self assert:0 equals:[[self visibleGridLineViews] count]];
}
- (void)testATableViewWithoutAnOverrideDrawsTheGridLinesAsViews
{
[tableView setGridStyleMask:CPTableViewSolidVerticalGridLineMask];
[tableView setGridColor:[CPColor redColor]];
[tableView layoutIfNeeded];
[self assert:2 equals:[[self visibleGridLineViews] count]];
}
// MARK: Row view state
/*
The table view sets the state of its row views. The look signal, setNeedsDisplay:, gives
every visible row view the state again and marks it for layout.
*/
- (void)testTheRowViewsShowTheStateOfTheTableViewAfterLayout
{
[tableView selectRowIndexes:[CPIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
[tableView setSelectionHighlightStyle:CPTableViewSelectionHighlightStyleSourceList];
[tableView layoutIfNeeded];
var rowView = [tableView rowViewAtRow:1 makeIfNecessary:NO];
[self assertTrue:[rowView isSelected]];
[self assertFalse:[rowView isEmphasized] message:@"the table view does not have the focus"];
[self assert:CPTableViewSelectionHighlightStyleSourceList equals:[rowView selectionHighlightStyle]];
[self assertTrue:[[tableView rowViewAtRow:0 makeIfNecessary:NO] isNextRowSelected]];
}
- (void)testAGridChangeMarksTheRowViewsForLayout
{
[[tableView subviews] makeObjectsPerformSelector:@selector(layoutIfNeeded)];
var rowView = [tableView rowViewAtRow:1 makeIfNecessary:NO];
[self assertFalse:[rowView needsLayout]];
[tableView setGridStyleMask:CPTableViewSolidHorizontalGridLineMask];
[self assertTrue:[rowView needsLayout]];
[self assertTrue:[tableView needsLayout]];
}
/*
A setter writes no look. The row view writes its look in its layout, under its effective
appearance.
*/
- (void)testARowViewWritesItsBackgroundInItsLayoutOnly
{
var colors = [[CPColor redColor], [CPColor greenColor]];
[[tableView subviews] makeObjectsPerformSelector:@selector(layoutIfNeeded)];
var rowView = [tableView rowViewAtRow:1 makeIfNecessary:NO],
writtenColor = rowView._backgroundColor;
[tableView setAlternatingRowBackgroundColors:colors];
[tableView setUsesAlternatingRowBackgroundColors:YES];
[self assert:colors[1] equals:[rowView backgroundColor] message:@"the state is current at once"];
[self assert:writtenColor same:rowView._backgroundColor message:@"nothing is written before the layout"];
[rowView layoutIfNeeded];
[self assert:colors[1] equals:rowView._backgroundColor];
}
/*
The group row colour applies outside the source-list style only.
*/
- (void)testAGroupRowHasTheGroupColorOutsideTheSourceListStyle
{
var color = [CPColor blueColor],
state = nil;
[tableView setValue:color forThemeAttribute:@"group-row-background-color"];
[tableView setDelegate:self];
state = [tableView _tableRowStateForRow:1];
[self assert:color equals:state.defaultBackgroundColor];
[tableView setSelectionHighlightStyle:CPTableViewSelectionHighlightStyleSourceList];
state = [tableView _tableRowStateForRow:1];
[self assertNull:state.defaultBackgroundColor];
}
- (BOOL)tableView:(CPTableView)aTableView isGroupRow:(CPInteger)aRow
{
return aRow === 1;
}
// MARK: Row views that draw on a canvas
- (void)testARowViewOfTheBaseClassTakesNoDisplayMarks
{
var rowView = [[CPTableRowView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 20.0)];
[rowView setNeedsDisplay:YES];
[self assertFalse:[rowView needsDisplay]];
}
- (void)testARowViewThatOverridesOneDrawMethodDrawsOnACanvas
{
var rowView = [[DrawingPassSeparatorRowView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 20.0)];
[rowView setNeedsDisplay:YES];
[self assertTrue:[rowView needsDisplay]];
}
/*
drawRect: calls the background, then the selection for a selected row, then the separator
when the grid has horizontal lines, then the feedback for a drop on the row.
*/
- (void)testARowViewDrawsItsPartsInAppKitOrder
{
var rowView = [[DrawingPassRecordingRowView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 20.0)];
[rowView _setTableView:tableView];
[tableView setGridStyleMask:CPTableViewSolidHorizontalGridLineMask];
[rowView setSelected:YES];
[rowView setTargetForDropOperation:YES];
[rowView drawRect:[rowView bounds]];
[self assert:[@"background", @"selection", @"separator", @"drop"] equals:DrawingPassRecord];
}
- (void)testARowViewDrawsOnlyThePartsThatApply
{
var rowView = [[DrawingPassRecordingRowView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 20.0)];
[rowView _setTableView:tableView];
[tableView setGridStyleMask:CPTableViewGridNone];
[rowView setSelected:YES];
[rowView setSelectionHighlightStyle:CPTableViewSelectionHighlightStyleNone];
[rowView drawRect:[rowView bounds]];
[self assert:[@"background"] equals:DrawingPassRecord];
}
@end