mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-29 09:52:03 +00:00
AppKit: Add previously missing public CPTableRowView with AppKit's row view API
- Replace _CPTableRowView with CPTableRowView: state properties, background colour with application and default values, viewAtColumn: and numberOfColumns - Set all row view state from table view in one method at attach, selection change, full update and drop target change - Write row view look in layoutSubviews instead of in setters - Add rowViewAtRow:makeIfNecessary:, enumerateAvailableRowViewsUsingBlock:, didAddRowView:forRow: and didRemoveRowView:forRow: - Accept row views in rowForView: - Add tableView:rowViewForRow:, tableView:didAddRowView:forRow: and tableView:didRemoveRowView:forRow: delegate methods, and outline view equivalents - Keep row views apart from data view loading, so column changes no longer recycle them - Keep private row views below last row, reuse table-made row views from pool and delegate row views by identifier - Return no unfocused selection colour for missing or CSS-based selection colour instead of raising - Add CPTableRowView tests
This commit is contained in:
1 parent
d2c365ef21
commit
18ac703f4e
13 files changed
+1716
-262
No files matched your search
+51
-2
@@ -81,7 +81,10 @@ var CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_
|
||||
CPOutlineViewDelegate_outlineView_willRemoveView_forTableColumn_item_ = 1 << 24,
|
||||
CPOutlineViewDelegate_selectionShouldChangeInOutlineView_ = 1 << 25,
|
||||
CPOutlineViewDelegate_outlineView_menuForTableColumn_item_ = 1 << 26,
|
||||
CPOutlineViewDelegate_outlineView_viewForTableColumn_item_ = 1 << 27;
|
||||
CPOutlineViewDelegate_outlineView_viewForTableColumn_item_ = 1 << 27,
|
||||
CPOutlineViewDelegate_outlineView_rowViewForItem_ = 1 << 28,
|
||||
CPOutlineViewDelegate_outlineView_didAddRowView_forRow_ = 1 << 29,
|
||||
CPOutlineViewDelegate_outlineView_didRemoveRowView_forRow_ = 1 << 30;
|
||||
|
||||
CPOutlineViewDropOnItemIndex = -1;
|
||||
|
||||
@@ -121,11 +124,14 @@ function SHOULD_SELECT_ITEM(anOutlineView, anItem)
|
||||
- (CPString)outlineView:(CPOutlineView)anOutlineView typeSelectStringForTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
|
||||
- (CPView)outlineView:(CPOutlineView)anOutlineView dataViewForTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
|
||||
- (CPView)outlineView:(CPOutlineView)anOutlineView viewForTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
|
||||
- (CPTableRowView)outlineView:(CPOutlineView)anOutlineView rowViewForItem:(id)anItem;
|
||||
- (float)outlineView:(CPOutlineView)anOutlineView heightOfRowByItem:(id)anItem;
|
||||
- (float)outlineView:(CPOutlineView)anOutlineView sizeToFitWidthOfColumn:(CPTableColumn)aTableColumn;
|
||||
- (id)outlineView:(CPOutlineView)anOutlineView nextTypeSelectMatchFromItem:(id)startItem toItem:(id)endItem forString:(CPString)searchString;
|
||||
- (void)outlineView:(CPOutlineView)anOutlineView didAddRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow;
|
||||
- (void)outlineView:(CPOutlineView)anOutlineView didClickTableColumn:(CPTableColumn)aTableColumn;
|
||||
- (void)outlineView:(CPOutlineView)anOutlineView didDragTableColumn:(CPTableColumn)aTableColumn;
|
||||
- (void)outlineView:(CPOutlineView)anOutlineView didRemoveRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow;
|
||||
- (void)outlineView:(CPOutlineView)anOutlineView mouseDownInHeaderOfTableColumn:(CPTableColumn)aTableColumn;
|
||||
- (void)outlineView:(CPOutlineView)anOutlineView willDisplayOutlineView:(CPView)aView forTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
|
||||
- (void)outlineView:(CPOutlineView)anOutlineView willDisplayView:(CPView)aView forTableColumn:(CPTableColumn)aTableColumn item:(id)anItem;
|
||||
@@ -1614,6 +1620,17 @@ function SHOULD_SELECT_ITEM(anOutlineView, anItem)
|
||||
Return YES if the item is a group item, otherwise NO.
|
||||
@code - (BOOL)outlineView:(CPOutlineView)outlineView isGroupItem:(id)item; @endcode
|
||||
|
||||
@section rowviews Row Views:
|
||||
|
||||
Return a row view for the row of an item, or nil for a CPTableRowView of the outline view's own.
|
||||
@code - (CPTableRowView)outlineView:(CPOutlineView)outlineView rowViewForItem:(id)item; @endcode
|
||||
|
||||
Called when the outline view has added a row view for a row.
|
||||
@code - (void)outlineView:(CPOutlineView)outlineView didAddRowView:(CPTableRowView)rowView forRow:(CPInteger)row; @endcode
|
||||
|
||||
Called when the outline view has removed a row view from a row. The row is -1 for a row that no longer exists.
|
||||
@code - (void)outlineView:(CPOutlineView)outlineView didRemoveRowView:(CPTableRowView)rowView forRow:(CPInteger)row; @endcode
|
||||
|
||||
|
||||
@section variableitems Variable Item Heights
|
||||
|
||||
@@ -1711,7 +1728,10 @@ function SHOULD_SELECT_ITEM(anOutlineView, anItem)
|
||||
CPOutlineViewDelegate_outlineView_willDisplayView_forTableColumn_item_ , @selector(outlineView:willDisplayView:forTableColumn:item:),
|
||||
CPOutlineViewDelegate_outlineView_willRemoveView_forTableColumn_item_ , @selector(outlineView:willRemoveView:forTableColumn:item:),
|
||||
CPOutlineViewDelegate_selectionShouldChangeInOutlineView_ , @selector(selectionShouldChangeInOutlineView:),
|
||||
CPOutlineViewDelegate_outlineView_menuForTableColumn_item_ , @selector(outlineView:menuForTableColumn:item:)
|
||||
CPOutlineViewDelegate_outlineView_menuForTableColumn_item_ , @selector(outlineView:menuForTableColumn:item:),
|
||||
CPOutlineViewDelegate_outlineView_rowViewForItem_ , @selector(outlineView:rowViewForItem:),
|
||||
CPOutlineViewDelegate_outlineView_didAddRowView_forRow_ , @selector(outlineView:didAddRowView:forRow:),
|
||||
CPOutlineViewDelegate_outlineView_didRemoveRowView_forRow_ , @selector(outlineView:didRemoveRowView:forRow:)
|
||||
],
|
||||
delegateCount = [delegateMethods count];
|
||||
|
||||
@@ -2016,6 +2036,15 @@ function SHOULD_SELECT_ITEM(anOutlineView, anItem)
|
||||
return rect;
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the indentation of the feedback for a drop on aRow: the indentation of the row's
|
||||
item.
|
||||
*/
|
||||
- (float)_indentationForDropOperationOnRow:(CPInteger)aRow
|
||||
{
|
||||
return [self levelForRow:aRow] * [self indentationPerLevel];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
@@ -2569,6 +2598,26 @@ function SHOULD_SELECT_ITEM(anOutlineView, anItem)
|
||||
}
|
||||
}
|
||||
|
||||
- (CPTableRowView)tableView:(CPTableView)aTableView rowViewForRow:(CPInteger)aRow
|
||||
{
|
||||
if ((_implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_rowViewForItem_))
|
||||
return [_outlineViewDelegate outlineView:self rowViewForItem:[self itemAtRow:aRow]];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)tableView:(CPTableView)aTableView didAddRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow
|
||||
{
|
||||
if ((_implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_didAddRowView_forRow_))
|
||||
[_outlineViewDelegate outlineView:self didAddRowView:aRowView forRow:aRow];
|
||||
}
|
||||
|
||||
- (void)tableView:(CPTableView)aTableView didRemoveRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow
|
||||
{
|
||||
if ((_implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_didRemoveRowView_forRow_))
|
||||
[_outlineViewDelegate outlineView:self didRemoveRowView:aRowView forRow:aRow];
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(CPTableView)aTableView isGroupRow:(CPInteger)aRow
|
||||
{
|
||||
if ((_implementedOutlineViewDelegateMethods & CPOutlineViewDelegate_outlineView_isGroupItem_))
|
||||
|
||||
@@ -0,0 +1,494 @@
|
||||
/*
|
||||
* CPTableRowView.j
|
||||
* AppKit
|
||||
*
|
||||
* Created by David Richardson on 2026-11-16.
|
||||
* 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 "CPTableViewCore.j"
|
||||
|
||||
@class CPTableView
|
||||
|
||||
|
||||
/*!
|
||||
@ingroup appkit
|
||||
@class CPTableRowView
|
||||
|
||||
A table view shows each visible row with a row view. The row view shows the state of its
|
||||
row: the background, the selection, the group row style, the horizontal separator and the
|
||||
feedback for a drop on the row.
|
||||
|
||||
The table view sets every property of a row view. A row view only shows its state: a
|
||||
change of \c selected on a row view does not change the selection of the table view.
|
||||
|
||||
An application changes the look of rows with a subclass. The delegate gives the table view
|
||||
an instance of the subclass in \c tableView:rowViewForRow:. The table view announces each
|
||||
row view that it adds with \c tableView:didAddRowView:forRow:, and each row view that it
|
||||
removes with \c tableView:didRemoveRowView:forRow:. A background colour that the
|
||||
application sets, for example in \c tableView:didAddRowView:forRow:, stays until the row
|
||||
view leaves its row.
|
||||
|
||||
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.
|
||||
*/
|
||||
@implementation CPTableRowView : CPView
|
||||
{
|
||||
BOOL _selected;
|
||||
BOOL _emphasized;
|
||||
BOOL _groupRowStyle;
|
||||
BOOL _previousRowSelected;
|
||||
BOOL _nextRowSelected;
|
||||
BOOL _targetForDropOperation;
|
||||
CPInteger _selectionHighlightStyle;
|
||||
CPInteger _draggingDestinationFeedbackStyle;
|
||||
float _indentationForDropOperation;
|
||||
|
||||
CPColor _rowBackgroundColor;
|
||||
CPColor _defaultRowBackgroundColor;
|
||||
|
||||
CPTableView _tableView;
|
||||
BOOL _isMadeByTableView;
|
||||
BOOL _isFillerRow;
|
||||
|
||||
CPView _separatorView;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)aFrame
|
||||
{
|
||||
self = [super initWithFrame:aFrame];
|
||||
|
||||
if (self)
|
||||
[self _initRowView];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
self = [super initWithCoder:aCoder];
|
||||
|
||||
if (self)
|
||||
[self _initRowView];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
Sets the state that a row view has before a table view configures it.
|
||||
*/
|
||||
- (void)_initRowView
|
||||
{
|
||||
_selectionHighlightStyle = CPTableViewSelectionHighlightStyleRegular;
|
||||
_draggingDestinationFeedbackStyle = CPTableViewDraggingDestinationFeedbackStyleRegular;
|
||||
_indentationForDropOperation = 0.0;
|
||||
|
||||
[self setHitTests:NO];
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets whether the row is selected. The table view sets this property.
|
||||
*/
|
||||
- (void)setSelected:(BOOL)isSelected
|
||||
{
|
||||
isSelected = !!isSelected;
|
||||
|
||||
if (_selected === isSelected)
|
||||
return;
|
||||
|
||||
_selected = isSelected;
|
||||
[self _rowStateDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns YES if the row is selected.
|
||||
*/
|
||||
- (BOOL)isSelected
|
||||
{
|
||||
return _selected;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets whether the row shows the emphasized look, the look of a selection in a table view
|
||||
that has the keyboard focus. The table view sets this property.
|
||||
*/
|
||||
- (void)setEmphasized:(BOOL)isEmphasized
|
||||
{
|
||||
isEmphasized = !!isEmphasized;
|
||||
|
||||
if (_emphasized === isEmphasized)
|
||||
return;
|
||||
|
||||
_emphasized = isEmphasized;
|
||||
[self _rowStateDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns YES if the row shows the emphasized look.
|
||||
*/
|
||||
- (BOOL)isEmphasized
|
||||
{
|
||||
return _emphasized;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets whether the row is a group row. The table view sets this property from the delegate
|
||||
method \c tableView:isGroupRow:.
|
||||
*/
|
||||
- (void)setGroupRowStyle:(BOOL)isGroupRowStyle
|
||||
{
|
||||
isGroupRowStyle = !!isGroupRowStyle;
|
||||
|
||||
if (_groupRowStyle === isGroupRowStyle)
|
||||
return;
|
||||
|
||||
_groupRowStyle = isGroupRowStyle;
|
||||
[self _rowStateDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns YES if the row is a group row.
|
||||
*/
|
||||
- (BOOL)isGroupRowStyle
|
||||
{
|
||||
return _groupRowStyle;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the selection highlight style: \c CPTableViewSelectionHighlightStyleNone,
|
||||
\c CPTableViewSelectionHighlightStyleRegular or
|
||||
\c CPTableViewSelectionHighlightStyleSourceList. The table view sets this property from
|
||||
its own style.
|
||||
*/
|
||||
- (void)setSelectionHighlightStyle:(CPInteger)aStyle
|
||||
{
|
||||
if (_selectionHighlightStyle === aStyle)
|
||||
return;
|
||||
|
||||
_selectionHighlightStyle = aStyle;
|
||||
[self _rowStateDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the selection highlight style.
|
||||
*/
|
||||
- (CPInteger)selectionHighlightStyle
|
||||
{
|
||||
return _selectionHighlightStyle;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets whether the row above this row is selected. The table view sets this property.
|
||||
*/
|
||||
- (void)setPreviousRowSelected:(BOOL)isPreviousRowSelected
|
||||
{
|
||||
isPreviousRowSelected = !!isPreviousRowSelected;
|
||||
|
||||
if (_previousRowSelected === isPreviousRowSelected)
|
||||
return;
|
||||
|
||||
_previousRowSelected = isPreviousRowSelected;
|
||||
[self _rowStateDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns YES if the row above this row is selected.
|
||||
*/
|
||||
- (BOOL)isPreviousRowSelected
|
||||
{
|
||||
return _previousRowSelected;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets whether the row below this row is selected. The table view sets this property.
|
||||
*/
|
||||
- (void)setNextRowSelected:(BOOL)isNextRowSelected
|
||||
{
|
||||
isNextRowSelected = !!isNextRowSelected;
|
||||
|
||||
if (_nextRowSelected === isNextRowSelected)
|
||||
return;
|
||||
|
||||
_nextRowSelected = isNextRowSelected;
|
||||
[self _rowStateDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns YES if the row below this row is selected.
|
||||
*/
|
||||
- (BOOL)isNextRowSelected
|
||||
{
|
||||
return _nextRowSelected;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets whether a drag proposes a drop on this row. The table view sets this property
|
||||
while a drag is over it.
|
||||
*/
|
||||
- (void)setTargetForDropOperation:(BOOL)isTargetForDropOperation
|
||||
{
|
||||
isTargetForDropOperation = !!isTargetForDropOperation;
|
||||
|
||||
if (_targetForDropOperation === isTargetForDropOperation)
|
||||
return;
|
||||
|
||||
_targetForDropOperation = isTargetForDropOperation;
|
||||
[self _rowStateDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns YES if a drag proposes a drop on this row.
|
||||
*/
|
||||
- (BOOL)isTargetForDropOperation
|
||||
{
|
||||
return _targetForDropOperation;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the style of the feedback for a drop:
|
||||
\c CPTableViewDraggingDestinationFeedbackStyleNone,
|
||||
\c CPTableViewDraggingDestinationFeedbackStyleRegular or
|
||||
\c CPTableViewDraggingDestinationFeedbackStyleSourceList. The table view sets this
|
||||
property from its own style.
|
||||
*/
|
||||
- (void)setDraggingDestinationFeedbackStyle:(CPInteger)aStyle
|
||||
{
|
||||
if (_draggingDestinationFeedbackStyle === aStyle)
|
||||
return;
|
||||
|
||||
_draggingDestinationFeedbackStyle = aStyle;
|
||||
[self _rowStateDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the style of the feedback for a drop.
|
||||
*/
|
||||
- (CPInteger)draggingDestinationFeedbackStyle
|
||||
{
|
||||
return _draggingDestinationFeedbackStyle;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the indentation of the feedback for a drop on this row. A table view sets 0. An
|
||||
outline view sets the indentation of the row's item.
|
||||
*/
|
||||
- (void)setIndentationForDropOperation:(float)anIndentation
|
||||
{
|
||||
anIndentation = +anIndentation || 0.0;
|
||||
|
||||
if (_indentationForDropOperation === anIndentation)
|
||||
return;
|
||||
|
||||
_indentationForDropOperation = anIndentation;
|
||||
[self _rowStateDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the indentation of the feedback for a drop on this row.
|
||||
*/
|
||||
- (float)indentationForDropOperation
|
||||
{
|
||||
return _indentationForDropOperation;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the background colour of the row. A nil colour gives the row its default
|
||||
background again. The colour stays until the row view leaves its row.
|
||||
*/
|
||||
- (void)setBackgroundColor:(CPColor)aColor
|
||||
{
|
||||
if (aColor === [CPNull null])
|
||||
aColor = nil;
|
||||
|
||||
if (_rowBackgroundColor === aColor)
|
||||
return;
|
||||
|
||||
_rowBackgroundColor = aColor;
|
||||
[self _rowStateDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the background colour of the row: the colour that the application set, else the
|
||||
default that the table view gives, else the background colour of the table view. The
|
||||
default is the group row colour for a group row, else the alternating colour of the row
|
||||
when the table view uses alternating colours.
|
||||
*/
|
||||
- (CPColor)backgroundColor
|
||||
{
|
||||
return _rowBackgroundColor || _defaultRowBackgroundColor || [_tableView backgroundColor];
|
||||
}
|
||||
|
||||
/*
|
||||
A row view archives only a background colour that the application set. The colour in the
|
||||
DOM can be the selection colour or a default of the table view.
|
||||
*/
|
||||
- (CPColor)_archivedBackgroundColor
|
||||
{
|
||||
return _rowBackgroundColor;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the view of the row in the given column, or nil when the row view is not in a
|
||||
table view or the column has no view.
|
||||
*/
|
||||
- (id)viewAtColumn:(CPInteger)aColumn
|
||||
{
|
||||
var row = [_tableView rowForView:self];
|
||||
|
||||
if (row === nil || row === CPNotFound)
|
||||
return nil;
|
||||
|
||||
return [_tableView viewAtColumn:aColumn row:row makeIfNecessary:NO];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the number of columns of the row: the number of columns of the table view, or 0
|
||||
when the row view is not in a table view.
|
||||
*/
|
||||
- (CPInteger)numberOfColumns
|
||||
{
|
||||
var row = [_tableView rowForView:self];
|
||||
|
||||
if (row === nil || row === CPNotFound)
|
||||
return 0;
|
||||
|
||||
return [_tableView numberOfColumns];
|
||||
}
|
||||
|
||||
/*
|
||||
A change of state marks the row view. The look follows in the layout, under the row
|
||||
view's effective appearance.
|
||||
*/
|
||||
- (void)_rowStateDidChange
|
||||
{
|
||||
[self setNeedsLayout];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
var color = nil;
|
||||
|
||||
if (_selected && _selectionHighlightStyle !== CPTableViewSelectionHighlightStyleNone)
|
||||
color = _emphasized ? [_tableView selectionHighlightColor] : [_tableView unfocusedSelectionHighlightColor];
|
||||
else
|
||||
color = _rowBackgroundColor || _defaultRowBackgroundColor;
|
||||
|
||||
[super setBackgroundColor:color];
|
||||
|
||||
[self _layoutSeparator];
|
||||
}
|
||||
|
||||
- (void)_layoutSeparator
|
||||
{
|
||||
if (_groupRowStyle || !([_tableView gridStyleMask] & CPTableViewSolidHorizontalGridLineMask))
|
||||
{
|
||||
[_separatorView setHidden:YES];
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_separatorView)
|
||||
{
|
||||
_separatorView = [[CPView alloc] initWithFrame:CGRectMakeZero()];
|
||||
[_separatorView setHitTests:NO];
|
||||
[_separatorView setAutoresizingMask:CPViewWidthSizable | CPViewMinYMargin];
|
||||
[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 setHidden:NO];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/*
|
||||
The table view's side of a row view. A table view calls these methods; an application
|
||||
does not.
|
||||
*/
|
||||
@implementation CPTableRowView (CPTableViewPrivate)
|
||||
|
||||
- (CPTableView)_tableView
|
||||
{
|
||||
return _tableView;
|
||||
}
|
||||
|
||||
- (void)_setTableView:(CPTableView)aTableView
|
||||
{
|
||||
_tableView = aTableView;
|
||||
}
|
||||
|
||||
/*
|
||||
Sets the background that the row has when the application set no colour.
|
||||
*/
|
||||
- (void)_setDefaultBackgroundColor:(CPColor)aColor
|
||||
{
|
||||
if (_defaultRowBackgroundColor === aColor)
|
||||
return;
|
||||
|
||||
_defaultRowBackgroundColor = aColor;
|
||||
[self _rowStateDidChange];
|
||||
}
|
||||
|
||||
/*
|
||||
YES for a row view that the table view made, which goes back to the table view's pool
|
||||
when it leaves its row.
|
||||
*/
|
||||
- (BOOL)_isMadeByTableView
|
||||
{
|
||||
return _isMadeByTableView;
|
||||
}
|
||||
|
||||
- (void)_setMadeByTableView:(BOOL)aFlag
|
||||
{
|
||||
_isMadeByTableView = aFlag;
|
||||
}
|
||||
|
||||
/*
|
||||
YES for a row view below the last row. Such a row view fills the empty area of the table
|
||||
view with the row look. It is private: the delegate never sees it.
|
||||
*/
|
||||
- (BOOL)_isFillerRow
|
||||
{
|
||||
return _isFillerRow;
|
||||
}
|
||||
|
||||
- (void)_setFillerRow:(BOOL)aFlag
|
||||
{
|
||||
_isFillerRow = aFlag;
|
||||
}
|
||||
|
||||
/*
|
||||
Ends the state that belongs to one row, when the row view leaves its row.
|
||||
*/
|
||||
- (void)_prepareForReuse
|
||||
{
|
||||
_rowBackgroundColor = nil;
|
||||
_targetForDropOperation = NO;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -285,6 +285,42 @@
|
||||
return [_delegate tableView:self dataViewForTableColumn:aTableColumn row:aRowIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return the row view that the delegate gives for the row. By default return nil.
|
||||
*/
|
||||
- (CPTableRowView)_sendDelegateRowViewForRow:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_rowViewForRow_))
|
||||
return nil;
|
||||
|
||||
return [_delegate tableView:self rowViewForRow:aRowIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Call the delegate tableView:didAddRowView:forRow:
|
||||
*/
|
||||
- (void)_sendDelegateDidAddRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_didAddRowView_forRow_))
|
||||
return;
|
||||
|
||||
[_delegate tableView:self didAddRowView:aRowView forRow:aRowIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Call the delegate tableView:didRemoveRowView:forRow:
|
||||
*/
|
||||
- (void)_sendDelegateDidRemoveRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_didRemoveRowView_forRow_))
|
||||
return;
|
||||
|
||||
[_delegate tableView:self didRemoveRowView:aRowView forRow:aRowIndex];
|
||||
}
|
||||
|
||||
|
||||
// MARK: -
|
||||
// MARK: Delegate methods to implement
|
||||
|
||||
@@ -85,6 +85,28 @@
|
||||
return row;
|
||||
}
|
||||
|
||||
/*
|
||||
Records aRow as the row that a drag proposes a drop on, or CPNotFound for none, and
|
||||
configures the row views of the old and the new row.
|
||||
*/
|
||||
- (void)_setDropTargetRow:(CPInteger)aRow
|
||||
{
|
||||
if (_dropTargetRow === aRow)
|
||||
return;
|
||||
|
||||
var oldRow = _dropTargetRow,
|
||||
oldRowView = _visibleRowViews[oldRow],
|
||||
newRowView = _visibleRowViews[aRow];
|
||||
|
||||
_dropTargetRow = aRow;
|
||||
|
||||
if (oldRowView)
|
||||
[self _configureRowView:oldRowView forRow:oldRow];
|
||||
|
||||
if (newRowView)
|
||||
[self _configureRowView:newRowView forRow:aRow];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
@@ -139,6 +161,8 @@
|
||||
else
|
||||
rect = [self _rectForDropHighlightViewOnRow:row];
|
||||
|
||||
[self _setDropTargetRow:(row !== -1 && dropOperation === CPTableViewDropOn && dragOperation !== CPDragOperationNone) ? row : CPNotFound];
|
||||
|
||||
[_dropOperationFeedbackView setDropOperation:row !== -1 ? dropOperation : CPDragOperationNone];
|
||||
[_dropOperationFeedbackView setHidden:(dragOperation == CPDragOperationNone)];
|
||||
[_dropOperationFeedbackView setFrame:rect];
|
||||
@@ -156,6 +180,7 @@
|
||||
// FIX ME: is there anything else that needs to happen here?
|
||||
// actual validation is called in draggingUpdated:
|
||||
[_dropOperationFeedbackView removeFromSuperview];
|
||||
[self _setDropTargetRow:CPNotFound];
|
||||
|
||||
return [self _dataSourceRespondsToValidateDropProposedRowProposedDropOperation];
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
}];
|
||||
|
||||
// 4. Z-Order Correction:
|
||||
// _CPTableRowViews (alternating row colors) are also added "Below nil".
|
||||
// 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)
|
||||
@@ -120,7 +120,7 @@
|
||||
|
||||
/*!
|
||||
Draws the background in a given clip rect.
|
||||
Deprecated: Handled by _CPTableRowView
|
||||
Deprecated: Handled by CPTableRowView
|
||||
*/
|
||||
- (void)drawBackgroundInClipRect:(CGRect)aRect
|
||||
{
|
||||
@@ -128,7 +128,7 @@
|
||||
|
||||
/*!
|
||||
Draws the grid for the tableview.
|
||||
Deprecated: Handled by _CPTableRowView
|
||||
Deprecated: Handled by CPTableRowView
|
||||
*/
|
||||
- (void)drawGridInClipRect:(CGRect)aRect
|
||||
{
|
||||
@@ -136,7 +136,7 @@
|
||||
|
||||
/*!
|
||||
Draws the selection.
|
||||
Deprecated: Handled by _CPTableRowView
|
||||
Deprecated: Handled by CPTableRowView
|
||||
*/
|
||||
- (void)highlightSelectionInClipRect:(CGRect)aRect
|
||||
{
|
||||
@@ -149,7 +149,7 @@
|
||||
*/
|
||||
- (void)_drawGroupRowsForRects:(CPArray)rects
|
||||
{
|
||||
// TODO: Implement Group Row styling in _CPTableRowView
|
||||
// TODO: Implement Group Row styling in CPTableRowView
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -243,7 +243,7 @@
|
||||
Returns the index of the row for the specified view.
|
||||
|
||||
@param view The view.
|
||||
@return The index of the row corresponding to the view. Returns -1 if the view is not a dataView, or a subview of a dataView.
|
||||
@return The index of the row corresponding to the view. Returns -1 if the view is not a dataView or a row view, or a subview of one.
|
||||
@discussion This is typically needed in the action method for a CPButton (or CPControl) to find out what row (and column) the action should be performed on.
|
||||
The implementation is O(rxc) where r is the number of visible rows, and c is the number of visible columns, so this method should generally not be called within a loop.
|
||||
*/
|
||||
@@ -253,6 +253,9 @@
|
||||
|
||||
[self getColumn:nil row:@ref(row) forView:aView];
|
||||
|
||||
if (row === -1)
|
||||
row = [self _rowOfRowViewContainingView:aView];
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
|
||||
@@ -174,22 +174,7 @@
|
||||
if (_selectionHighlightStyle !== CPTableViewSelectionHighlightStyleNone)
|
||||
[self _enumerateViewsInRows:newRows columns:_exposedColumns usingBlock:_BlockSelectView];
|
||||
|
||||
|
||||
// Update Row Views (DOM Backgrounds)
|
||||
var focused = [self _isFocused];
|
||||
[oldRows enumerateIndexesUsingBlock:function(idx, stop) {
|
||||
var rowView = _visibleRowViews[idx];
|
||||
|
||||
if (rowView)
|
||||
[rowView setSelected:NO focused:focused];
|
||||
}];
|
||||
|
||||
[newRows enumerateIndexesUsingBlock:function(idx, stop) {
|
||||
var rowView = _visibleRowViews[idx];
|
||||
|
||||
if (rowView)
|
||||
[rowView setSelected:YES focused:focused];
|
||||
}];
|
||||
[self _configureRowViewsForSelectionChangeFromRows:oldRows toRows:newRows];
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -311,6 +311,7 @@
|
||||
- (void)draggingExited:(id)sender
|
||||
{
|
||||
[_dropOperationFeedbackView removeFromSuperview];
|
||||
[self _setDropTargetRow:CPNotFound];
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -330,6 +331,7 @@
|
||||
_retargetedDropRow = nil;
|
||||
_draggedRowIndexes = [CPIndexSet indexSet];
|
||||
[_dropOperationFeedbackView removeFromSuperview];
|
||||
[self _setDropTargetRow:CPNotFound];
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
@import "CPTableViewCore.j"
|
||||
@import "CPTableRowView.j"
|
||||
|
||||
|
||||
@class CPButton
|
||||
@@ -45,6 +46,7 @@
|
||||
{
|
||||
if (_reloadAllRows)
|
||||
{
|
||||
[self _removeAllRowViews];
|
||||
[self _unloadDataViewsInRows:_exposedRows columns:_exposedColumns];
|
||||
|
||||
_exposedRows = [CPIndexSet indexSet];
|
||||
@@ -74,6 +76,8 @@
|
||||
[previouslyExposedRows removeIndexes:newlyExposedRows];
|
||||
[previouslyExposedColumns removeIndexes:newlyExposedColumns];
|
||||
|
||||
var addedRowViewRows = [self _updateRowViewsForRows:exposedRows];
|
||||
|
||||
[self _unloadDataViewsInRows:previouslyExposedRows columns:obscuredColumns];
|
||||
[self _unloadDataViewsInRows:obscuredRows columns:previouslyExposedColumns];
|
||||
[self _unloadDataViewsInRows:obscuredRows columns:obscuredColumns];
|
||||
@@ -86,6 +90,8 @@
|
||||
_exposedRows = exposedRows;
|
||||
_exposedColumns = exposedColumns;
|
||||
|
||||
[self _announceRowViewsInRows:addedRowViewRows];
|
||||
|
||||
// Remove old draw view call
|
||||
// [_tableDrawView setFrame:exposedRect];
|
||||
|
||||
@@ -197,18 +203,6 @@
|
||||
*/
|
||||
- (void)_unloadDataViewsInRows:(CPIndexSet)rowIndexes columns:(CPIndexSet)columnIndexes
|
||||
{
|
||||
// Recycle Row Views
|
||||
[rowIndexes enumerateIndexesUsingBlock:function(rowIndex, stop) {
|
||||
var rowView = _visibleRowViews[rowIndex];
|
||||
|
||||
if (rowView)
|
||||
{
|
||||
[rowView removeFromSuperview];
|
||||
_cachedRowViews.push(rowView);
|
||||
delete _visibleRowViews[rowIndex];
|
||||
}
|
||||
}];
|
||||
|
||||
if (![rowIndexes count] || ![columnIndexes count] || [columnIndexes lastIndex] >= [_tableColumns count])
|
||||
return;
|
||||
|
||||
@@ -235,42 +229,7 @@
|
||||
*/
|
||||
- (void)_loadDataViewsInRows:(CPIndexSet)rowIndexes columns:(CPIndexSet)columnIndexes
|
||||
{
|
||||
// Load Row Views
|
||||
var focused = [self _isFocused],
|
||||
visibleWidth = MAX([self bounds].size.width, CGRectGetWidth([self exposedRect])),
|
||||
delegateRespondsToGroupRow = (_implementedDelegateMethods & CPTableViewDelegate_tableView_isGroupRow_);
|
||||
|
||||
[rowIndexes enumerateIndexesUsingBlock:function(rowIndex, stop) {
|
||||
|
||||
var isGroupRow = delegateRespondsToGroupRow && [_delegate tableView:self isGroupRow:rowIndex];
|
||||
|
||||
if (!_visibleRowViews[rowIndex])
|
||||
{
|
||||
var rowView = [self _dequeueRowView];
|
||||
if (!rowView)
|
||||
rowView = [[_CPTableRowView alloc] initWithTableView:self];
|
||||
|
||||
[rowView setIsGroupRow:isGroupRow];
|
||||
[rowView setRowIndex:rowIndex];
|
||||
[rowView setSelected:[self isRowSelected:rowIndex] focused:focused];
|
||||
|
||||
// Set frame to span the entire width
|
||||
var rowRect = [self _rectOfRow:rowIndex checkRange:NO];
|
||||
rowRect.size.width = visibleWidth;
|
||||
rowRect.origin.x = 0;
|
||||
|
||||
[rowView setFrame:rowRect];
|
||||
|
||||
// Add behind data views
|
||||
[self addSubview:rowView positioned:CPWindowBelow relativeTo:nil];
|
||||
_visibleRowViews[rowIndex] = rowView;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update state of existing view
|
||||
[_visibleRowViews[rowIndex] setIsGroupRow:isGroupRow];
|
||||
}
|
||||
}];
|
||||
var focused = [self _isFocused];
|
||||
|
||||
if (![rowIndexes count] || ![columnIndexes count])
|
||||
return;
|
||||
@@ -296,8 +255,7 @@
|
||||
isRowSelected = [self isRowSelected:rowIndex],
|
||||
row = rowIndex;
|
||||
|
||||
// Note: Even for group rows, we iterate all columns to render their data.
|
||||
// The background styling is handled by the _CPTableRowView above.
|
||||
// Even for group rows, all columns get their data views. The row view draws the row's look.
|
||||
[columnIndexes enumerateIndexesUsingBlock:function(columnIndex, stopCol)
|
||||
{
|
||||
var tableColumn = _tableColumns[columnIndex],
|
||||
@@ -315,38 +273,346 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (CPView)_dequeueRowView
|
||||
/*
|
||||
Returns the frame of the row view of a row: the row's rect, over the full width of the
|
||||
table view.
|
||||
*/
|
||||
- (CGRect)_frameOfRowViewAtRow:(CPInteger)aRow
|
||||
{
|
||||
var rect = [self _rectOfRow:aRow checkRange:NO];
|
||||
|
||||
rect.origin.x = 0.0;
|
||||
rect.size.width = MAX(CGRectGetWidth([self bounds]), CGRectGetWidth([self exposedRect]));
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
/*
|
||||
Gives each row in rowIndexes a row view, and removes the row views of other rows. A row
|
||||
view made below the last row for a row that is now a real row, or the reverse, is
|
||||
replaced. Returns the real rows that got a row view, in ascending order, for the
|
||||
announcement.
|
||||
*/
|
||||
- (CPArray)_updateRowViewsForRows:(CPIndexSet)rowIndexes
|
||||
{
|
||||
var numberOfRows = [self numberOfRows],
|
||||
addedRows = [];
|
||||
|
||||
for (var key in _visibleRowViews)
|
||||
{
|
||||
if (!_visibleRowViews.hasOwnProperty(key))
|
||||
continue;
|
||||
|
||||
var row = +key;
|
||||
|
||||
if (![rowIndexes containsIndex:row] || [_visibleRowViews[key] _isFillerRow] !== (row >= numberOfRows))
|
||||
[self _removeRowViewAtRow:row];
|
||||
}
|
||||
|
||||
[rowIndexes enumerateIndexesUsingBlock:function(row, stop)
|
||||
{
|
||||
if (_visibleRowViews[row])
|
||||
return;
|
||||
|
||||
var rowView = [self _addRowViewAtRow:row];
|
||||
|
||||
if (![rowView _isFillerRow])
|
||||
addedRows.push(row);
|
||||
}];
|
||||
|
||||
return addedRows;
|
||||
}
|
||||
|
||||
/*
|
||||
Announces the row views of the rows in anArray, which the table view has added.
|
||||
*/
|
||||
- (void)_announceRowViewsInRows:(CPArray)anArray
|
||||
{
|
||||
for (var i = 0, count = anArray.length; i < count; i++)
|
||||
{
|
||||
var row = anArray[i],
|
||||
rowView = _visibleRowViews[row];
|
||||
|
||||
if (rowView)
|
||||
[self didAddRowView:rowView forRow:row];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Makes, configures and adds the row view of aRow, behind the views of the row, and returns
|
||||
it. A row below the last row gets a row view of the table view's own: such a row view is
|
||||
never given to the delegate.
|
||||
*/
|
||||
- (CPTableRowView)_addRowViewAtRow:(CPInteger)aRow
|
||||
{
|
||||
var isFillerRow = aRow >= [self numberOfRows],
|
||||
rowView = isFillerRow ? nil : [self _sendDelegateRowViewForRow:aRow];
|
||||
|
||||
if (rowView)
|
||||
[rowView _setMadeByTableView:NO];
|
||||
else
|
||||
{
|
||||
rowView = [self _dequeueRowView] || [[CPTableRowView alloc] initWithFrame:CGRectMakeZero()];
|
||||
[rowView _setMadeByTableView:YES];
|
||||
}
|
||||
|
||||
[rowView _setFillerRow:isFillerRow];
|
||||
[rowView setFrame:[self _frameOfRowViewAtRow:aRow]];
|
||||
|
||||
[self _configureRowView:rowView forRow:aRow];
|
||||
[rowView setNeedsLayout];
|
||||
|
||||
[self addSubview:rowView positioned:CPWindowBelow relativeTo:nil];
|
||||
_visibleRowViews[aRow] = rowView;
|
||||
|
||||
return rowView;
|
||||
}
|
||||
|
||||
/*
|
||||
Removes the row view of aRow and announces the removal. The row view goes back to the
|
||||
table view's pool when the table view made it, to the reuse queue of
|
||||
makeViewWithIdentifier:owner: when it has an identifier, and is released otherwise.
|
||||
*/
|
||||
- (void)_removeRowViewAtRow:(CPInteger)aRow
|
||||
{
|
||||
var rowView = _visibleRowViews[aRow];
|
||||
|
||||
if (!rowView)
|
||||
return;
|
||||
|
||||
delete _visibleRowViews[aRow];
|
||||
[rowView removeFromSuperview];
|
||||
|
||||
if (![rowView _isFillerRow])
|
||||
[self didRemoveRowView:rowView forRow:(aRow < [self numberOfRows] ? aRow : -1)];
|
||||
|
||||
[rowView _prepareForReuse];
|
||||
|
||||
if ([rowView _isMadeByTableView])
|
||||
_cachedRowViews.push(rowView);
|
||||
else if ([rowView identifier])
|
||||
[self _enqueueReusableDataView:rowView];
|
||||
}
|
||||
|
||||
/*
|
||||
Removes every row view.
|
||||
*/
|
||||
- (void)_removeAllRowViews
|
||||
{
|
||||
for (var key in _visibleRowViews)
|
||||
{
|
||||
if (_visibleRowViews.hasOwnProperty(key))
|
||||
[self _removeRowViewAtRow:+key];
|
||||
}
|
||||
}
|
||||
|
||||
- (CPTableRowView)_dequeueRowView
|
||||
{
|
||||
if (_cachedRowViews.length > 0)
|
||||
return _cachedRowViews.pop();
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
/*
|
||||
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 isFillerRow = aRow >= [self numberOfRows],
|
||||
isGroupRow = !isFillerRow && [self _sendDelegateIsGroupRow:aRow],
|
||||
defaultColor = nil;
|
||||
|
||||
if (isGroupRow)
|
||||
defaultColor = [self valueForThemeAttribute:@"group-row-background-color"];
|
||||
else if (_usesAlternatingRowBackgroundColors)
|
||||
{
|
||||
var colors = [self alternatingRowBackgroundColors],
|
||||
count = [colors count];
|
||||
|
||||
if (count)
|
||||
defaultColor = colors[aRow % count];
|
||||
}
|
||||
|
||||
[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]];
|
||||
}
|
||||
|
||||
/*
|
||||
Configures the row views of the rows whose selection changed between oldRows and
|
||||
newRows, and of their neighbours, whose previous and next row state can change.
|
||||
*/
|
||||
- (void)_configureRowViewsForSelectionChangeFromRows:(CPIndexSet)oldRows toRows:(CPIndexSet)newRows
|
||||
{
|
||||
var isChanged = function(aRow)
|
||||
{
|
||||
return aRow >= 0 && [oldRows containsIndex:aRow] !== [newRows containsIndex:aRow];
|
||||
};
|
||||
|
||||
for (var key in _visibleRowViews)
|
||||
{
|
||||
if (!_visibleRowViews.hasOwnProperty(key))
|
||||
continue;
|
||||
|
||||
var row = +key;
|
||||
|
||||
if (isChanged(row - 1) || isChanged(row) || isChanged(row + 1))
|
||||
[self _configureRowView:_visibleRowViews[key] forRow:row];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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
|
||||
{
|
||||
var focused = [self _isFocused];
|
||||
for (var idx in _visibleRowViews)
|
||||
for (var key in _visibleRowViews)
|
||||
{
|
||||
if (_visibleRowViews.hasOwnProperty(idx))
|
||||
[_visibleRowViews[idx] setSelected:[self isRowSelected:+idx] focused:focused];
|
||||
if (!_visibleRowViews.hasOwnProperty(key))
|
||||
continue;
|
||||
|
||||
var rowView = _visibleRowViews[key];
|
||||
|
||||
[self _configureRowView:rowView forRow:+key];
|
||||
[rowView setNeedsLayout];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_updateAllVisibleRowViewsFrames
|
||||
{
|
||||
var visibleWidth = MAX([self bounds].size.width, CGRectGetWidth([self exposedRect]));
|
||||
for (var idx in _visibleRowViews)
|
||||
for (var key in _visibleRowViews)
|
||||
{
|
||||
if (_visibleRowViews.hasOwnProperty(idx))
|
||||
{
|
||||
var rowView = _visibleRowViews[idx],
|
||||
rect = [rowView frame];
|
||||
rect.size.width = visibleWidth;
|
||||
[rowView setFrame:rect];
|
||||
}
|
||||
if (_visibleRowViews.hasOwnProperty(key))
|
||||
[_visibleRowViews[key] setFrame:[self _frameOfRowViewAtRow:+key]];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the indentation of the feedback for a drop on aRow. A table view has none.
|
||||
*/
|
||||
- (float)_indentationForDropOperationOnRow:(CPInteger)aRow
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the row of the row view that is aView or contains it, or -1. Row views below the
|
||||
last row are private and give -1.
|
||||
*/
|
||||
- (CPInteger)_rowOfRowViewContainingView:(CPView)aView
|
||||
{
|
||||
var view = aView;
|
||||
|
||||
while (view && [view superview] !== self)
|
||||
view = [view superview];
|
||||
|
||||
if (!view)
|
||||
return -1;
|
||||
|
||||
var numberOfRows = [self numberOfRows];
|
||||
|
||||
for (var key in _visibleRowViews)
|
||||
{
|
||||
if (_visibleRowViews.hasOwnProperty(key) && _visibleRowViews[key] === view && +key < numberOfRows)
|
||||
return +key;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the row view of a row.
|
||||
|
||||
@param row The index of the row.
|
||||
@param makeIfNecessary YES to make a row view when the row has none.
|
||||
@return The row view, or nil when the row has none and \c makeIfNecessary is NO.
|
||||
|
||||
@discussion
|
||||
A row view that this method makes is temporary: the table view removes it at its next
|
||||
layout when the row is not on screen.
|
||||
|
||||
An exception is raised when \c row is not a row of the table view.
|
||||
*/
|
||||
- (id)rowViewAtRow:(CPInteger)aRow makeIfNecessary:(BOOL)makeIfNecessary
|
||||
{
|
||||
if (aRow < 0 || aRow > (_numberOfRows - 1))
|
||||
[CPException raise:CPInvalidArgumentException
|
||||
reason:@"Row " + aRow + " out of row range [0-" + (_numberOfRows - 1) + "] for rowViewAtRow:makeIfNecessary:"];
|
||||
|
||||
var rowView = _visibleRowViews[aRow];
|
||||
|
||||
if (rowView && ![rowView _isFillerRow])
|
||||
return rowView;
|
||||
|
||||
if (!makeIfNecessary)
|
||||
return nil;
|
||||
|
||||
if (rowView)
|
||||
[self _removeRowViewAtRow:aRow];
|
||||
|
||||
rowView = [self _addRowViewAtRow:aRow];
|
||||
[self didAddRowView:rowView forRow:aRow];
|
||||
|
||||
// The next layout removes the row view if the row is not on screen.
|
||||
[self setNeedsLayout];
|
||||
|
||||
return rowView;
|
||||
}
|
||||
|
||||
/*!
|
||||
Calls handler for each row view of a row on screen, in ascending order of the rows.
|
||||
|
||||
@param handler A function that takes two arguments: the row view and its row.
|
||||
*/
|
||||
- (void)enumerateAvailableRowViewsUsingBlock:(Function/*CPTableRowView rowView, CPInteger row*/)handler
|
||||
{
|
||||
var numberOfRows = [self numberOfRows],
|
||||
rows = [];
|
||||
|
||||
for (var key in _visibleRowViews)
|
||||
{
|
||||
if (_visibleRowViews.hasOwnProperty(key) && +key < numberOfRows)
|
||||
rows.push(+key);
|
||||
}
|
||||
|
||||
rows.sort(function(lhs, rhs) { return lhs - rhs; });
|
||||
|
||||
for (var i = 0, count = rows.length; i < count; i++)
|
||||
handler(_visibleRowViews[rows[i]], rows[i]);
|
||||
}
|
||||
|
||||
/*!
|
||||
Called when the table view has added a row view for a row. A subclass can override this
|
||||
method to change the row view or add views to it. Call super: the default implementation
|
||||
sends \c tableView:didAddRowView:forRow: to the delegate.
|
||||
*/
|
||||
- (void)didAddRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow
|
||||
{
|
||||
[self _sendDelegateDidAddRowView:aRowView forRow:aRow];
|
||||
}
|
||||
|
||||
/*!
|
||||
Called when the table view has removed a row view from a row. The table view can reuse the
|
||||
row view, so a subclass should remove views that it added. The row is -1 for a row that no
|
||||
longer exists. Call super: the default implementation sends
|
||||
\c tableView:didRemoveRowView:forRow: to the delegate.
|
||||
*/
|
||||
- (void)didRemoveRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow
|
||||
{
|
||||
[self _sendDelegateDidRemoveRowView:aRowView forRow:aRow];
|
||||
}
|
||||
|
||||
- (CPView)preparedViewAtColumn:(CPInteger)column row:(CPInteger)row
|
||||
{
|
||||
return [self _preparedViewAtColumn:column row:row isRowSelected:[self isRowSelected:row]];
|
||||
@@ -467,16 +733,12 @@
|
||||
[view setFrame:[self frameOfDataViewAtColumn:column row:row]];
|
||||
}];
|
||||
|
||||
// Also layout row views if needed (usually handled by resize)
|
||||
var visibleWidth = MAX([self bounds].size.width, CGRectGetWidth([self exposedRect]));
|
||||
[rowIndexes enumerateIndexesUsingBlock:function(row, stop) {
|
||||
if (_visibleRowViews[row])
|
||||
{
|
||||
var rect = [self _rectOfRow:row checkRange:NO];
|
||||
rect.size.width = visibleWidth;
|
||||
rect.origin.x = 0;
|
||||
[_visibleRowViews[row] setFrame:rect];
|
||||
}
|
||||
[rowIndexes enumerateIndexesUsingBlock:function(row, stop)
|
||||
{
|
||||
var rowView = _visibleRowViews[row];
|
||||
|
||||
if (rowView)
|
||||
[rowView setFrame:[self _frameOfRowViewAtRow:row]];
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
*/
|
||||
|
||||
@import "CPTableViewCore.j"
|
||||
@import "_CPTableRowView.j"
|
||||
@import "CPTableRowView.j"
|
||||
@import "CPTableView+Columns.j"
|
||||
@import "CPTableView+Selection.j"
|
||||
@import "CPTableView+Layout.j"
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
@class CPClipView
|
||||
@class CPButton
|
||||
@class _CPDropOperationDrawingView
|
||||
@class CPTableRowView
|
||||
|
||||
@global CPApp
|
||||
|
||||
@@ -88,7 +89,10 @@ CPTableViewDelegate_selectionShouldChangeInTableView_
|
||||
CPTableViewDelegate_tableViewSelectionDidChange_ = 1 << 22,
|
||||
CPTableViewDelegate_tableViewSelectionIsChanging_ = 1 << 23,
|
||||
CPTableViewDelegate_tableViewMenuForTableColumn_row_ = 1 << 24,
|
||||
CPTableViewDelegate_tableView_shouldReorderColumn_toColumn_ = 1 << 25;
|
||||
CPTableViewDelegate_tableView_shouldReorderColumn_toColumn_ = 1 << 25,
|
||||
CPTableViewDelegate_tableView_rowViewForRow_ = 1 << 26,
|
||||
CPTableViewDelegate_tableView_didAddRowView_forRow_ = 1 << 27,
|
||||
CPTableViewDelegate_tableView_didRemoveRowView_forRow_ = 1 << 28;
|
||||
|
||||
//CPTableViewDraggingDestinationFeedbackStyles
|
||||
CPTableViewDraggingDestinationFeedbackStyleNone = -1;
|
||||
@@ -153,9 +157,12 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
|
||||
- (CPString)tableView:(CPTableView)aTableView typeSelectStringForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex;
|
||||
- (CPView)tableView:(CPTableView)aTableView dataViewForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex;
|
||||
- (CPView)tableView:(CPTableView)aTableView viewForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex;
|
||||
- (CPTableRowView)tableView:(CPTableView)aTableView rowViewForRow:(CPInteger)aRowIndex;
|
||||
- (float)tableView:(CPTableView)aTableView heightOfRow:(CPInteger)aRowIndex;
|
||||
- (void)tableView:(CPTableView)aTableView didAddRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRowIndex;
|
||||
- (void)tableView:(CPTableView)aTableView didClickTableColumn:(CPTableColumn)aTableColumn;
|
||||
- (void)tableView:(CPTableView)aTableView didDragTableColumn:(CPTableColumn)aTableColumn;
|
||||
- (void)tableView:(CPTableView)aTableView didRemoveRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRowIndex;
|
||||
- (void)tableView:(CPTableView)aTableView mouseDownInHeaderOfTableColumn:(CPTableColumn)aTableColumn;
|
||||
- (void)tableView:(CPTableView)aTableView willDisplayView:(CPView)aView forTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex;
|
||||
- (void)tableView:(CPTableView)aTableView willRemoveView:(CPView)aView forTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex;
|
||||
@@ -213,7 +220,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
|
||||
CPDictionary _archivedDataViews;
|
||||
Object _unavailable_custom_cibs;
|
||||
|
||||
// Row View Management (DOM Composition)
|
||||
// Row views: the visible row views by row, and the pool of row views that the table view made
|
||||
Object _visibleRowViews;
|
||||
CPArray _cachedRowViews;
|
||||
|
||||
@@ -282,6 +289,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
|
||||
CPDragOperation _dragOperationDefaultMask;
|
||||
int _retargetedDropRow;
|
||||
CPDragOperation _retargetedDropOperation;
|
||||
CPInteger _dropTargetRow;
|
||||
|
||||
BOOL _disableAutomaticResizing @accessors(property=disableAutomaticResizing);
|
||||
BOOL _lastColumnShouldSnap;
|
||||
@@ -438,9 +446,9 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
|
||||
|
||||
_groupRows = [CPIndexSet indexSet];
|
||||
|
||||
// Row View Initialization for DOM rendering
|
||||
_visibleRowViews = { };
|
||||
_cachedRowViews = [];
|
||||
_dropTargetRow = CPNotFound;
|
||||
|
||||
_draggedColumnIndex = -1;
|
||||
_draggedColumnIsSelected = NO;
|
||||
@@ -1082,6 +1090,15 @@ NOT YET IMPLEMENTED
|
||||
|
||||
- (CPColor)_unfocusedSelectionColorFromColor:(CPColor)aColor saturation:(float)saturation
|
||||
{
|
||||
/*
|
||||
A table view without a selection colour, as under no theme, and a colour that CSS
|
||||
defines, which has no components, gave no hue: the method read the first element of a
|
||||
null array and raised. A row view that laid out in that state stopped the display
|
||||
server, so no later layout ran. Such a colour has no unfocused variant.
|
||||
*/
|
||||
if (!aColor || [aColor isCSSBased])
|
||||
return nil;
|
||||
|
||||
var hsb = [aColor hsbComponents];
|
||||
|
||||
return [CPColor colorWithHue:hsb[0] saturation:hsb[1] * saturation brightness:hsb[2]];
|
||||
@@ -1452,6 +1469,35 @@ When using bindings, this method is optional if at least one identifier has been
|
||||
|
||||
The autoresizingMask of the returned view will automatically be set to CPViewNotSizable if the data view was created in Interface builder in a table column. Otherwise, for example if the view is created manually in code, this method expects the data view to have a CPViewNotSizable mask.
|
||||
|
||||
Returns the row view for the specified row.
|
||||
@code
|
||||
- (CPTableRowView)tableView:(CPTableView)tableView rowViewForRow:(CPInteger)row
|
||||
@endcode
|
||||
|
||||
@discussion
|
||||
Implement this method to give rows a subclass of CPTableRowView. The table view sets the
|
||||
properties of the row view before it adds it. Returning nil is acceptable: the table view then
|
||||
uses a CPTableRowView of its own. A row view with an identifier goes to the reuse queue of
|
||||
makeViewWithIdentifier:owner: when it leaves the screen.
|
||||
|
||||
Called when the table view has added a row view for a row.
|
||||
@code
|
||||
- (void)tableView:(CPTableView)tableView didAddRowView:(CPTableRowView)rowView forRow:(CPInteger)row
|
||||
@endcode
|
||||
|
||||
@discussion
|
||||
The delegate can set properties of the row view here, such as its background colour, or add
|
||||
views to it.
|
||||
|
||||
Called when the table view has removed a row view from a row.
|
||||
@code
|
||||
- (void)tableView:(CPTableView)tableView didRemoveRowView:(CPTableRowView)rowView forRow:(CPInteger)row
|
||||
@endcode
|
||||
|
||||
@discussion
|
||||
The table view can reuse the row view, so the delegate should remove any views that it added.
|
||||
The row is -1 for a row that no longer exists.
|
||||
|
||||
|
||||
@section displayingcells Displaying Cells:
|
||||
|
||||
@@ -1591,6 +1637,15 @@ Your delegate can implement this method to avoid subclassing the tableview to ad
|
||||
|
||||
[self _updateIsViewBased];
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(tableView:rowViewForRow:)])
|
||||
_implementedDelegateMethods |= CPTableViewDelegate_tableView_rowViewForRow_;
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(tableView:didAddRowView:forRow:)])
|
||||
_implementedDelegateMethods |= CPTableViewDelegate_tableView_didAddRowView_forRow_;
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(tableView:didRemoveRowView:forRow:)])
|
||||
_implementedDelegateMethods |= CPTableViewDelegate_tableView_didRemoveRowView_forRow_;
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(tableView:didClickTableColumn:)])
|
||||
_implementedDelegateMethods |= CPTableViewDelegate_tableView_didClickTableColumn_;
|
||||
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
* _CPTableRowView.j
|
||||
* AppKit
|
||||
*
|
||||
* Created by Francisco Tolmasky.
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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 "CPTableViewCore.j"
|
||||
|
||||
|
||||
@class CPButton
|
||||
@class CPClipView
|
||||
@class CPUserDefaults
|
||||
@class CPTableHeaderView
|
||||
@class CPTableView
|
||||
@class _CPTableColumnHeaderView
|
||||
@class CPClipView
|
||||
@class CPButton
|
||||
@class _CPDropOperationDrawingView
|
||||
|
||||
|
||||
// Internal class to handle row background, selection and grid lines via DOM/CSS
|
||||
@implementation _CPTableRowView : CPView
|
||||
{
|
||||
CPInteger _rowIndex;
|
||||
CPTableView _tableView;
|
||||
CPView _gridLineView;
|
||||
BOOL _selected;
|
||||
BOOL _focused;
|
||||
BOOL _isGroupRow;
|
||||
}
|
||||
|
||||
- (id)initWithTableView:(CPTableView)aTableView
|
||||
{
|
||||
self = [super initWithFrame:CGRectMakeZero()];
|
||||
if (self)
|
||||
{
|
||||
_tableView = aTableView;
|
||||
_selected = NO;
|
||||
_focused = NO;
|
||||
_isGroupRow = NO;
|
||||
|
||||
[self setHitTests:NO];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setRowIndex:(CPInteger)anIndex
|
||||
{
|
||||
_rowIndex = anIndex;
|
||||
[self updateState];
|
||||
}
|
||||
|
||||
// New method to toggle group row state
|
||||
- (void)setIsGroupRow:(BOOL)isGroupRow
|
||||
{
|
||||
if (_isGroupRow === isGroupRow)
|
||||
return;
|
||||
|
||||
_isGroupRow = isGroupRow;
|
||||
[self updateState];
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)isSelected focused:(BOOL)isFocused
|
||||
{
|
||||
if (_selected === isSelected && _focused === isFocused)
|
||||
return;
|
||||
|
||||
_selected = isSelected;
|
||||
_focused = isFocused;
|
||||
[self updateState];
|
||||
}
|
||||
|
||||
- (void)updateState
|
||||
{
|
||||
if (!CPDOMAvailable)
|
||||
return;
|
||||
|
||||
var backgroundColor = nil;
|
||||
|
||||
if (_selected && [_tableView selectionHighlightStyle] != CPTableViewSelectionHighlightStyleNone)
|
||||
{
|
||||
if (_focused)
|
||||
backgroundColor = [_tableView selectionHighlightColor];
|
||||
else
|
||||
backgroundColor = [_tableView unfocusedSelectionHighlightColor];
|
||||
}
|
||||
else if (_isGroupRow)
|
||||
{
|
||||
// Apply group row background
|
||||
backgroundColor = [_tableView valueForThemeAttribute:@"group-row-background-color"];
|
||||
}
|
||||
else if ([_tableView usesAlternatingRowBackgroundColors])
|
||||
{
|
||||
var colors = [_tableView alternatingRowBackgroundColors];
|
||||
if ([colors count] > 0)
|
||||
backgroundColor = colors[_rowIndex % [colors count]];
|
||||
}
|
||||
|
||||
if (!backgroundColor)
|
||||
backgroundColor = [CPColor clearColor];
|
||||
|
||||
[self setBackgroundColor:backgroundColor];
|
||||
[self _updateGridLine];
|
||||
}
|
||||
|
||||
- (void)_updateGridLine
|
||||
{
|
||||
// Don't draw grid lines on group rows
|
||||
if (_isGroupRow)
|
||||
{
|
||||
[_gridLineView setHidden:YES];
|
||||
return;
|
||||
}
|
||||
|
||||
var mask = [_tableView gridStyleMask];
|
||||
|
||||
if (mask & CPTableViewSolidHorizontalGridLineMask)
|
||||
{
|
||||
if (!_gridLineView)
|
||||
{
|
||||
_gridLineView = [[CPView alloc] initWithFrame:CGRectMakeZero()];
|
||||
[_gridLineView setBackgroundColor:[_tableView gridColor]];
|
||||
[_gridLineView setAutoresizingMask:CPViewWidthSizable | CPViewMinYMargin];
|
||||
[self addSubview:_gridLineView];
|
||||
}
|
||||
|
||||
var thickness = [_tableView valueForThemeAttribute:@"grid-line-thickness"] || 1.0;
|
||||
[_gridLineView setFrame:CGRectMake(0, CGRectGetHeight([self bounds]) - thickness, CGRectGetWidth([self bounds]), thickness)];
|
||||
[_gridLineView setHidden:NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
[_gridLineView setHidden:YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)resizeWithOldSuperviewSize:(CGSize)oldSize
|
||||
{
|
||||
[super resizeWithOldSuperviewSize:oldSize];
|
||||
if (_gridLineView && ![_gridLineView isHidden])
|
||||
[self _updateGridLine];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,703 @@
|
||||
/*
|
||||
* CPTableRowViewTest.j
|
||||
* AppKit
|
||||
*
|
||||
* Created by David Richardson on 2026-11-16.
|
||||
* 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>
|
||||
|
||||
var RowViewTestDragType = @"RowViewTestDragType";
|
||||
|
||||
/*
|
||||
A row view class that a delegate gives to the table view.
|
||||
*/
|
||||
@implementation _RowViewTestRowView : CPTableRowView
|
||||
@end
|
||||
|
||||
/*
|
||||
A table view subclass that records the calls of the two subclass hooks.
|
||||
*/
|
||||
@implementation _RowViewTestTableView : CPTableView
|
||||
{
|
||||
CPArray hookAddedRows @accessors;
|
||||
CPArray hookRemovedRows @accessors;
|
||||
}
|
||||
|
||||
- (void)didAddRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow
|
||||
{
|
||||
[hookAddedRows addObject:aRow];
|
||||
[super didAddRowView:aRowView forRow:aRow];
|
||||
}
|
||||
|
||||
- (void)didRemoveRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow
|
||||
{
|
||||
[hookRemovedRows addObject:aRow];
|
||||
[super didRemoveRowView:aRowView forRow:aRow];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
The data source of the table view, and a delegate that can give row views.
|
||||
*/
|
||||
@implementation _RowViewTestDataSource : CPObject
|
||||
{
|
||||
CPInteger numberOfRows @accessors;
|
||||
}
|
||||
|
||||
- (CPInteger)numberOfRowsInTableView:(CPTableView)aTableView
|
||||
{
|
||||
return numberOfRows;
|
||||
}
|
||||
|
||||
- (id)tableView:(CPTableView)aTableView objectValueForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRow
|
||||
{
|
||||
return @"Value " + aRow;
|
||||
}
|
||||
|
||||
- (CPDragOperation)tableView:(CPTableView)aTableView validateDrop:(id)anInfo proposedRow:(CPInteger)aRow proposedDropOperation:(CPTableViewDropOperation)anOperation
|
||||
{
|
||||
return CPDragOperationMove;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation _RowViewTestDelegate : CPObject
|
||||
{
|
||||
CPArray rowViewRequests @accessors;
|
||||
CPArray addedRows @accessors;
|
||||
CPArray removedRows @accessors;
|
||||
CPArray selectionAtAdd @accessors;
|
||||
CPIndexSet groupRows @accessors;
|
||||
CPString rowViewIdentifier @accessors;
|
||||
CPInteger rowViewsMade @accessors;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
{
|
||||
rowViewRequests = [];
|
||||
addedRows = [];
|
||||
removedRows = [];
|
||||
selectionAtAdd = [];
|
||||
groupRows = [CPIndexSet indexSet];
|
||||
rowViewsMade = 0;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CPTableRowView)tableView:(CPTableView)aTableView rowViewForRow:(CPInteger)aRow
|
||||
{
|
||||
[rowViewRequests addObject:aRow];
|
||||
|
||||
var rowView = rowViewIdentifier ? [aTableView makeViewWithIdentifier:rowViewIdentifier owner:self] : nil;
|
||||
|
||||
if (!rowView)
|
||||
{
|
||||
rowView = [[_RowViewTestRowView alloc] initWithFrame:CGRectMakeZero()];
|
||||
[rowView setIdentifier:rowViewIdentifier];
|
||||
rowViewsMade++;
|
||||
}
|
||||
|
||||
return rowView;
|
||||
}
|
||||
|
||||
- (void)tableView:(CPTableView)aTableView didAddRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow
|
||||
{
|
||||
[addedRows addObject:aRow];
|
||||
[selectionAtAdd addObject:[aRowView isSelected]];
|
||||
}
|
||||
|
||||
- (void)tableView:(CPTableView)aTableView didRemoveRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow
|
||||
{
|
||||
[removedRows addObject:aRow];
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(CPTableView)aTableView isGroupRow:(CPInteger)aRow
|
||||
{
|
||||
return [groupRows containsIndex:aRow];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation _RowViewTestDraggingInfo : CPObject
|
||||
{
|
||||
CPPasteboard draggingPasteboard @accessors;
|
||||
CGPoint draggingLocation @accessors;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
An outline view's data source and delegate: two root items, A with the children A1 and
|
||||
A2, and B.
|
||||
*/
|
||||
@implementation _RowViewTestOutlineDataSource : CPObject
|
||||
{
|
||||
CPArray requestedItems @accessors;
|
||||
CPArray addedRows @accessors;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
{
|
||||
requestedItems = [];
|
||||
addedRows = [];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CPArray)_childrenOfItem:(id)anItem
|
||||
{
|
||||
if (anItem === nil)
|
||||
return [@"A", @"B"];
|
||||
|
||||
if (anItem === @"A")
|
||||
return [@"A1", @"A2"];
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
- (id)outlineView:(CPOutlineView)anOutlineView child:(CPInteger)anIndex ofItem:(id)anItem
|
||||
{
|
||||
return [self _childrenOfItem:anItem][anIndex];
|
||||
}
|
||||
|
||||
- (BOOL)outlineView:(CPOutlineView)anOutlineView isItemExpandable:(id)anItem
|
||||
{
|
||||
return [[self _childrenOfItem:anItem] count] > 0;
|
||||
}
|
||||
|
||||
- (CPInteger)outlineView:(CPOutlineView)anOutlineView numberOfChildrenOfItem:(id)anItem
|
||||
{
|
||||
return [[self _childrenOfItem:anItem] count];
|
||||
}
|
||||
|
||||
- (id)outlineView:(CPOutlineView)anOutlineView objectValueForTableColumn:(CPTableColumn)aColumn byItem:(id)anItem
|
||||
{
|
||||
return anItem;
|
||||
}
|
||||
|
||||
- (CPDragOperation)outlineView:(CPOutlineView)anOutlineView validateDrop:(id)anInfo proposedItem:(id)anItem proposedChildIndex:(CPInteger)anIndex
|
||||
{
|
||||
return CPDragOperationMove;
|
||||
}
|
||||
|
||||
- (CPTableRowView)outlineView:(CPOutlineView)anOutlineView rowViewForItem:(id)anItem
|
||||
{
|
||||
[requestedItems addObject:anItem];
|
||||
|
||||
return [[_RowViewTestRowView alloc] initWithFrame:CGRectMakeZero()];
|
||||
}
|
||||
|
||||
- (void)outlineView:(CPOutlineView)anOutlineView didAddRowView:(CPTableRowView)aRowView forRow:(CPInteger)aRow
|
||||
{
|
||||
[addedRows addObject:aRow];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/*
|
||||
Each visible row of a table view has a row view, a CPTableRowView, with AppKit's API. The
|
||||
table view sets every property of a row view; a row view only shows its state. A delegate
|
||||
can give the row views, and hears of each row view that the table view adds or removes.
|
||||
*/
|
||||
@implementation CPTableRowViewTest : OJTestCase
|
||||
{
|
||||
CPWindow theWindow;
|
||||
CPScrollView scrollView;
|
||||
_RowViewTestTableView tableView;
|
||||
_RowViewTestDataSource dataSource;
|
||||
_RowViewTestDelegate delegate;
|
||||
}
|
||||
|
||||
- (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];
|
||||
|
||||
/*
|
||||
The table view is the document view of a scroll view, so the area below the last row
|
||||
is part of the exposed rect.
|
||||
*/
|
||||
scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 200.0)];
|
||||
tableView = [[_RowViewTestTableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 200.0)];
|
||||
[tableView setHookAddedRows:[]];
|
||||
[tableView setHookRemovedRows:[]];
|
||||
|
||||
var column = [[CPTableColumn alloc] initWithIdentifier:@"Column"];
|
||||
|
||||
[column setWidth:150.0];
|
||||
[tableView addTableColumn:column];
|
||||
|
||||
dataSource = [[_RowViewTestDataSource alloc] init];
|
||||
[dataSource setNumberOfRows:5];
|
||||
[tableView setDataSource:dataSource];
|
||||
|
||||
[scrollView setDocumentView:tableView];
|
||||
[[theWindow contentView] addSubview:scrollView];
|
||||
|
||||
[self reload];
|
||||
}
|
||||
|
||||
/*
|
||||
Reloads the table view and lays it out, as the display cycle does.
|
||||
*/
|
||||
- (void)reload
|
||||
{
|
||||
[tableView reloadData];
|
||||
[tableView load];
|
||||
}
|
||||
|
||||
/*
|
||||
Gives the table view a delegate that gives row views, and reloads it. The records start
|
||||
after the reload.
|
||||
*/
|
||||
- (void)useDelegate
|
||||
{
|
||||
delegate = [[_RowViewTestDelegate alloc] init];
|
||||
[tableView setDelegate:delegate];
|
||||
[self reload];
|
||||
|
||||
[delegate setRemovedRows:[]];
|
||||
[tableView setHookRemovedRows:[]];
|
||||
}
|
||||
|
||||
- (CPTableRowView)rowViewAtRow:(CPInteger)aRow
|
||||
{
|
||||
return [tableView rowViewAtRow:aRow makeIfNecessary:NO];
|
||||
}
|
||||
|
||||
/*
|
||||
Returns every row view among the subviews of the table view, the private ones below the
|
||||
last row included.
|
||||
*/
|
||||
- (CPArray)allRowViews
|
||||
{
|
||||
var subviews = [tableView subviews],
|
||||
rowViews = [];
|
||||
|
||||
for (var i = 0, count = [subviews count]; i < count; i++)
|
||||
{
|
||||
if ([subviews[i] isKindOfClass:[CPTableRowView class]])
|
||||
rowViews.push(subviews[i]);
|
||||
}
|
||||
|
||||
return rowViews;
|
||||
}
|
||||
|
||||
- (CPArray)rowsOfAvailableRowViews
|
||||
{
|
||||
var rows = [];
|
||||
|
||||
[tableView enumerateAvailableRowViewsUsingBlock:function(aRowView, aRow)
|
||||
{
|
||||
rows.push(aRow);
|
||||
}];
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
- (CPArray)sorted:(CPArray)anArray
|
||||
{
|
||||
return [anArray copy].sort(function(lhs, rhs) { return lhs - rhs; });
|
||||
}
|
||||
|
||||
- (void)testEachRowOnScreenHasARowView
|
||||
{
|
||||
for (var row = 0; row < 5; row++)
|
||||
[self assertTrue:[[self rowViewAtRow:row] isKindOfClass:[CPTableRowView class]] message:@"row " + row];
|
||||
}
|
||||
|
||||
- (void)testARowViewSpansTheFullWidthOfItsRow
|
||||
{
|
||||
var rowView = [self rowViewAtRow:2],
|
||||
rowRect = [tableView rectOfRow:2];
|
||||
|
||||
[self assert:0.0 equals:CGRectGetMinX([rowView frame])];
|
||||
[self assert:CGRectGetWidth([tableView bounds]) equals:CGRectGetWidth([rowView frame])];
|
||||
[self assert:CGRectGetMinY(rowRect) equals:CGRectGetMinY([rowView frame])];
|
||||
[self assert:CGRectGetHeight(rowRect) equals:CGRectGetHeight([rowView frame])];
|
||||
}
|
||||
|
||||
- (void)testARowViewLiesBehindTheViewsOfItsRow
|
||||
{
|
||||
var subviews = [tableView subviews],
|
||||
rowView = [self rowViewAtRow:1],
|
||||
dataView = [tableView viewAtColumn:0 row:1 makeIfNecessary:NO];
|
||||
|
||||
[self assertTrue:[subviews indexOfObjectIdenticalTo:rowView] < [subviews indexOfObjectIdenticalTo:dataView]];
|
||||
}
|
||||
|
||||
- (void)testARowViewTakesNoMouseEvents
|
||||
{
|
||||
[self assertFalse:[[self rowViewAtRow:0] hitTests]];
|
||||
[self assertFalse:[[[CPTableRowView alloc] initWithFrame:CGRectMakeZero()] hitTests]];
|
||||
}
|
||||
|
||||
- (void)testRowViewAtRowRaisesForARowOutsideTheTable
|
||||
{
|
||||
[self assertThrows:function() { [tableView rowViewAtRow:5 makeIfNecessary:NO]; }];
|
||||
[self assertThrows:function() { [tableView rowViewAtRow:-1 makeIfNecessary:YES]; }];
|
||||
}
|
||||
|
||||
/*
|
||||
Rows below the last row have row views too, so that the row look fills the empty area.
|
||||
These row views are private.
|
||||
*/
|
||||
- (void)testRowsBelowTheLastRowHavePrivateRowViews
|
||||
{
|
||||
[self useDelegate];
|
||||
|
||||
[self assertTrue:[[self allRowViews] count] > 5 message:@"the area below the last row has row views"];
|
||||
[self assert:[0, 1, 2, 3, 4] equals:[self rowsOfAvailableRowViews]];
|
||||
[self assert:[0, 1, 2, 3, 4] equals:[self sorted:[delegate rowViewRequests]]];
|
||||
[self assert:[0, 1, 2, 3, 4] equals:[self sorted:[delegate addedRows]]];
|
||||
|
||||
var rowViews = [self allRowViews];
|
||||
|
||||
for (var i = 0, count = [rowViews count]; i < count; i++)
|
||||
{
|
||||
if ([tableView rowForView:rowViews[i]] === -1)
|
||||
[self assert:[CPTableRowView class] equals:[rowViews[i] class] message:@"a row view below the last row"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testEnumerationVisitsEachRowViewInAscendingOrder
|
||||
{
|
||||
var rowViews = [];
|
||||
|
||||
[tableView enumerateAvailableRowViewsUsingBlock:function(aRowView, aRow)
|
||||
{
|
||||
[self assert:[self rowViewAtRow:aRow] same:aRowView];
|
||||
rowViews.push(aRow);
|
||||
}];
|
||||
|
||||
[self assert:[0, 1, 2, 3, 4] equals:rowViews];
|
||||
}
|
||||
|
||||
- (void)testTheSelectionReachesTheRowViews
|
||||
{
|
||||
[tableView selectRowIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(1, 2)] byExtendingSelection:NO];
|
||||
|
||||
[self assertFalse:[[self rowViewAtRow:0] isSelected]];
|
||||
[self assertTrue:[[self rowViewAtRow:1] isSelected]];
|
||||
[self assertTrue:[[self rowViewAtRow:2] isSelected]];
|
||||
[self assertFalse:[[self rowViewAtRow:3] isSelected]];
|
||||
|
||||
[self assertTrue:[[self rowViewAtRow:0] isNextRowSelected]];
|
||||
[self assertFalse:[[self rowViewAtRow:1] isPreviousRowSelected]];
|
||||
[self assertTrue:[[self rowViewAtRow:1] isNextRowSelected]];
|
||||
[self assertTrue:[[self rowViewAtRow:2] isPreviousRowSelected]];
|
||||
[self assertFalse:[[self rowViewAtRow:2] isNextRowSelected]];
|
||||
[self assertTrue:[[self rowViewAtRow:3] isPreviousRowSelected]];
|
||||
|
||||
[tableView deselectAll:nil];
|
||||
|
||||
for (var row = 0; row < 5; row++)
|
||||
{
|
||||
var rowView = [self rowViewAtRow:row];
|
||||
|
||||
[self assertFalse:[rowView isSelected] message:@"row " + row];
|
||||
[self assertFalse:[rowView isPreviousRowSelected] message:@"row " + row];
|
||||
[self assertFalse:[rowView isNextRowSelected] message:@"row " + row];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
A row view of a selected row lays out when the table view has no selection colour, as
|
||||
under no theme. The table view derived the unfocused colour from no colour and raised,
|
||||
and the exception stopped the display server for every later layout.
|
||||
*/
|
||||
- (void)testASelectedRowViewLaysOutWithoutASelectionColor
|
||||
{
|
||||
[tableView selectRowIndexes:[CPIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
|
||||
|
||||
var rowView = [self rowViewAtRow:1];
|
||||
|
||||
[self assertNull:[tableView selectionHighlightColor] message:@"the test needs a table view without a selection colour"];
|
||||
[self assertTrue:[rowView needsLayout]];
|
||||
|
||||
[rowView layoutIfNeeded];
|
||||
|
||||
[self assertFalse:[rowView needsLayout]];
|
||||
}
|
||||
|
||||
- (void)testSelectingARowViewDoesNotSelectTheRow
|
||||
{
|
||||
[[self rowViewAtRow:1] setSelected:YES];
|
||||
|
||||
[self assert:0 equals:[[tableView selectedRowIndexes] count]];
|
||||
}
|
||||
|
||||
- (void)testRowViewsAreNotEmphasizedWithoutTheFocus
|
||||
{
|
||||
[tableView selectRowIndexes:[CPIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
|
||||
|
||||
[self assertFalse:[[self rowViewAtRow:1] isEmphasized]];
|
||||
}
|
||||
|
||||
- (void)testTheHighlightStyleReachesTheRowViews
|
||||
{
|
||||
[self assert:CPTableViewSelectionHighlightStyleRegular equals:[[self rowViewAtRow:0] selectionHighlightStyle]];
|
||||
[self assert:CPTableViewDraggingDestinationFeedbackStyleRegular equals:[[self rowViewAtRow:0] draggingDestinationFeedbackStyle]];
|
||||
|
||||
[tableView setSelectionHighlightStyle:CPTableViewSelectionHighlightStyleSourceList];
|
||||
|
||||
for (var row = 0; row < 5; row++)
|
||||
{
|
||||
[self assert:CPTableViewSelectionHighlightStyleSourceList equals:[[self rowViewAtRow:row] selectionHighlightStyle] message:@"row " + row];
|
||||
[self assert:CPTableViewDraggingDestinationFeedbackStyleSourceList equals:[[self rowViewAtRow:row] draggingDestinationFeedbackStyle] message:@"row " + row];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testAGroupRowHasTheGroupRowStyle
|
||||
{
|
||||
delegate = [[_RowViewTestDelegate alloc] init];
|
||||
[delegate setGroupRows:[CPIndexSet indexSetWithIndex:1]];
|
||||
[tableView setDelegate:delegate];
|
||||
[self reload];
|
||||
|
||||
[self assertFalse:[[self rowViewAtRow:0] isGroupRowStyle]];
|
||||
[self assertTrue:[[self rowViewAtRow:1] isGroupRowStyle]];
|
||||
}
|
||||
|
||||
- (void)testTheDelegateGivesTheRowViews
|
||||
{
|
||||
[tableView selectRowIndexes:[CPIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
|
||||
[tableView setHookAddedRows:[]];
|
||||
[self useDelegate];
|
||||
|
||||
for (var row = 0; row < 5; row++)
|
||||
[self assert:[_RowViewTestRowView class] equals:[[self rowViewAtRow:row] class] message:@"row " + row];
|
||||
|
||||
[self assert:[0, 1, 2, 3, 4] equals:[delegate addedRows]];
|
||||
[self assert:[0, 1, 2, 3, 4] equals:[tableView hookAddedRows]];
|
||||
[self assert:[NO, YES, NO, NO, NO] equals:[delegate selectionAtAdd] message:@"a row view is configured before the table view announces it"];
|
||||
}
|
||||
|
||||
- (void)testARowViewThatLeavesItsRowIsAnnounced
|
||||
{
|
||||
[self useDelegate];
|
||||
|
||||
[dataSource setNumberOfRows:2];
|
||||
[self reload];
|
||||
|
||||
[self assert:[-1, -1, -1, 0, 1] equals:[self sorted:[delegate removedRows]]];
|
||||
[self assert:[-1, -1, -1, 0, 1] equals:[self sorted:[tableView hookRemovedRows]]];
|
||||
}
|
||||
|
||||
- (void)testRowViewAtRowCanMakeARowViewForARowOffScreen
|
||||
{
|
||||
[dataSource setNumberOfRows:30];
|
||||
[self useDelegate];
|
||||
|
||||
[self assertNull:[self rowViewAtRow:25]];
|
||||
|
||||
var rowView = [tableView rowViewAtRow:25 makeIfNecessary:YES];
|
||||
|
||||
[self assertTrue:[rowView isKindOfClass:[CPTableRowView class]]];
|
||||
[self assert:rowView same:[self rowViewAtRow:25]];
|
||||
[self assertTrue:[[delegate addedRows] containsObject:25]];
|
||||
|
||||
// The row view is temporary: the next layout removes it.
|
||||
[tableView load];
|
||||
|
||||
[self assertNull:[self rowViewAtRow:25]];
|
||||
[self assertTrue:[[delegate removedRows] containsObject:25]];
|
||||
}
|
||||
|
||||
- (void)testRowForViewAcceptsARowView
|
||||
{
|
||||
var rowView = [self rowViewAtRow:3],
|
||||
subview = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 10.0, 10.0)];
|
||||
|
||||
[rowView addSubview:subview];
|
||||
|
||||
[self assert:3 equals:[tableView rowForView:rowView]];
|
||||
[self assert:3 equals:[tableView rowForView:subview]];
|
||||
[self assert:-1 equals:[tableView columnForView:rowView]];
|
||||
[self assert:-1 equals:[tableView rowForView:[[CPTableRowView alloc] initWithFrame:CGRectMakeZero()]]];
|
||||
}
|
||||
|
||||
- (void)testARowViewGivesTheViewsOfItsRow
|
||||
{
|
||||
var rowView = [self rowViewAtRow:2];
|
||||
|
||||
[self assert:1 equals:[rowView numberOfColumns]];
|
||||
[self assert:[tableView viewAtColumn:0 row:2 makeIfNecessary:NO] same:[rowView viewAtColumn:0]];
|
||||
[self assert:0 equals:[[[CPTableRowView alloc] initWithFrame:CGRectMakeZero()] numberOfColumns]];
|
||||
}
|
||||
|
||||
/*
|
||||
A row view's background colour is the colour that the application set, else the
|
||||
alternating colour of the row, else the background colour of the table view.
|
||||
*/
|
||||
- (void)testTheBackgroundColorDefaultsToTheTableViewBackground
|
||||
{
|
||||
[tableView setBackgroundColor:[CPColor yellowColor]];
|
||||
|
||||
[self assert:[CPColor yellowColor] equals:[[self rowViewAtRow:1] backgroundColor]];
|
||||
}
|
||||
|
||||
- (void)testTheBackgroundColorIsTheAlternatingColorOfTheRow
|
||||
{
|
||||
var colors = [[CPColor redColor], [CPColor greenColor]];
|
||||
|
||||
[tableView setAlternatingRowBackgroundColors:colors];
|
||||
[tableView setUsesAlternatingRowBackgroundColors:YES];
|
||||
|
||||
for (var row = 0; row < 5; row++)
|
||||
[self assert:colors[row % 2] equals:[[self rowViewAtRow:row] backgroundColor] message:@"row " + row];
|
||||
}
|
||||
|
||||
- (void)testABackgroundColorThatTheApplicationSetsStaysUntilTheRowViewLeavesItsRow
|
||||
{
|
||||
var rowView = [self rowViewAtRow:1],
|
||||
color = [CPColor blueColor];
|
||||
|
||||
[tableView setBackgroundColor:[CPColor yellowColor]];
|
||||
[rowView setBackgroundColor:color];
|
||||
[tableView selectRowIndexes:[CPIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
|
||||
|
||||
[self assert:color same:[rowView backgroundColor]];
|
||||
|
||||
[self reload];
|
||||
|
||||
[self assert:[CPColor yellowColor] equals:[rowView backgroundColor]];
|
||||
}
|
||||
|
||||
/*
|
||||
The table view keeps a pool for the row views that it makes. A row view from the delegate
|
||||
that has an identifier goes to the queue of makeViewWithIdentifier:owner:.
|
||||
*/
|
||||
- (void)testTheTableViewReusesItsOwnRowViews
|
||||
{
|
||||
var oldRowViews = [self allRowViews];
|
||||
|
||||
[self reload];
|
||||
|
||||
var newRowViews = [self allRowViews];
|
||||
|
||||
[self assert:[oldRowViews count] equals:[newRowViews count]];
|
||||
|
||||
for (var i = 0; i < [newRowViews count]; i++)
|
||||
[self assertTrue:[oldRowViews containsObjectIdenticalTo:newRowViews[i]] message:@"row view " + i];
|
||||
}
|
||||
|
||||
- (void)testADelegateRowViewWithAnIdentifierIsReused
|
||||
{
|
||||
delegate = [[_RowViewTestDelegate alloc] init];
|
||||
[delegate setRowViewIdentifier:@"RowView"];
|
||||
[tableView setDelegate:delegate];
|
||||
[self reload];
|
||||
[self reload];
|
||||
|
||||
[self assert:5 equals:[delegate rowViewsMade]];
|
||||
}
|
||||
|
||||
- (void)testADelegateRowViewWithoutAnIdentifierIsNotReused
|
||||
{
|
||||
[self useDelegate];
|
||||
[self reload];
|
||||
|
||||
[self assert:10 equals:[delegate rowViewsMade]];
|
||||
}
|
||||
|
||||
- (void)testTheRowOfAProposedDropIsTheTargetForTheDrop
|
||||
{
|
||||
[tableView registerForDraggedTypes:[RowViewTestDragType]];
|
||||
|
||||
var info = [[_RowViewTestDraggingInfo alloc] init],
|
||||
pasteboard = [CPPasteboard pasteboardWithName:CPDragPboard];
|
||||
|
||||
[pasteboard declareTypes:[RowViewTestDragType] owner:self];
|
||||
[info setDraggingPasteboard:pasteboard];
|
||||
[info setDraggingLocation:[tableView convertPoint:CGPointMake(50.0, CGRectGetMidY([tableView rectOfRow:2])) toView:nil]];
|
||||
|
||||
[tableView draggingUpdated:info];
|
||||
|
||||
for (var row = 0; row < 5; row++)
|
||||
[self assert:(row === 2) equals:[[self rowViewAtRow:row] isTargetForDropOperation] message:@"row " + row];
|
||||
|
||||
[self assert:0.0 equals:[[self rowViewAtRow:2] indentationForDropOperation]];
|
||||
|
||||
[tableView draggingExited:info];
|
||||
|
||||
[self assertFalse:[[self rowViewAtRow:2] isTargetForDropOperation]];
|
||||
}
|
||||
|
||||
/*
|
||||
An outline view gives its delegate the row views of items, and sets the indentation of a
|
||||
drop to the indentation of the row's item.
|
||||
*/
|
||||
- (void)testAnOutlineViewDelegateGivesTheRowViewsOfItems
|
||||
{
|
||||
var outlineView = [[CPOutlineView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 200.0)],
|
||||
outlineDataSource = [[_RowViewTestOutlineDataSource alloc] init],
|
||||
column = [[CPTableColumn alloc] initWithIdentifier:@"Column"];
|
||||
|
||||
[outlineView addTableColumn:column];
|
||||
[outlineView setOutlineTableColumn:column];
|
||||
[outlineView setDataSource:outlineDataSource];
|
||||
[outlineView setDelegate:outlineDataSource];
|
||||
[[theWindow contentView] addSubview:outlineView];
|
||||
|
||||
[outlineView expandItem:@"A"];
|
||||
|
||||
[outlineDataSource setRequestedItems:[]];
|
||||
[outlineDataSource setAddedRows:[]];
|
||||
|
||||
[outlineView reloadData];
|
||||
[outlineView load];
|
||||
|
||||
[self assert:[@"A", @"A1", @"A2", @"B"] equals:[outlineDataSource requestedItems]];
|
||||
[self assert:[0, 1, 2, 3] equals:[outlineDataSource addedRows]];
|
||||
[self assert:[_RowViewTestRowView class] equals:[[outlineView rowViewAtRow:1 makeIfNecessary:NO] class]];
|
||||
|
||||
[outlineView registerForDraggedTypes:[RowViewTestDragType]];
|
||||
|
||||
var info = [[_RowViewTestDraggingInfo alloc] init],
|
||||
pasteboard = [CPPasteboard pasteboardWithName:CPDragPboard],
|
||||
childRow = [outlineView rowForItem:@"A1"];
|
||||
|
||||
[pasteboard declareTypes:[RowViewTestDragType] owner:self];
|
||||
[info setDraggingPasteboard:pasteboard];
|
||||
[info setDraggingLocation:[outlineView convertPoint:CGPointMake(100.0, CGRectGetMidY([outlineView rectOfRow:childRow])) toView:nil]];
|
||||
|
||||
[outlineView draggingUpdated:info];
|
||||
|
||||
var rowView = [outlineView rowViewAtRow:childRow makeIfNecessary:NO];
|
||||
|
||||
[self assertTrue:[rowView isTargetForDropOperation]];
|
||||
[self assert:[outlineView indentationPerLevel] equals:[rowView indentationForDropOperation]];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user