mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-28 01:12:03 +00:00
AppKit: Divide CPTableView into core file and category files
- Move class, instance variables, initialization and display attributes to CPTableViewCore.j - Move columns, selection, layout, views, drawing, tracking, dragging, responder and editing methods to categories, one file each - Move existing data source, delegate, bindings and coding categories to files of their own - Move _CPTableRowView and CPTableCellView to files of their own - Import all files from CPTableView.j - Make data source and delegate flag constants global for use across files
This commit is contained in:
1 parent
00c3972fa5
commit
d2c365ef21
18 files changed
+7230
-6613
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* CPTableCellView.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
|
||||
|
||||
|
||||
@implementation CPTableCellView : CPView
|
||||
{
|
||||
id _objectValue @accessors(property=objectValue);
|
||||
|
||||
CPTextField _textField @accessors(property=textField);
|
||||
CPImageView _imageView @accessors(property=imageView);
|
||||
}
|
||||
|
||||
- (void)awakeFromCib
|
||||
{
|
||||
[super awakeFromCib];
|
||||
[self setThemeState:CPThemeStateTableDataView];
|
||||
}
|
||||
|
||||
- (BOOL)setThemeState:(ThemeState)aState
|
||||
{
|
||||
[super setThemeState:aState];
|
||||
[self recursivelyPerformSelector:@selector(setThemeState:) withObject:aState startingFrom:self];
|
||||
}
|
||||
|
||||
- (BOOL)unsetThemeState:(ThemeState)aState
|
||||
{
|
||||
[super unsetThemeState:aState];
|
||||
[self recursivelyPerformSelector:@selector(unsetThemeState:) withObject:aState startingFrom:self];
|
||||
}
|
||||
|
||||
- (void)recursivelyPerformSelector:(SEL)selector withObject:(id)anObject startingFrom:(id)aView
|
||||
{
|
||||
[[aView subviews] enumerateObjectsUsingBlock:function(view, idx)
|
||||
{
|
||||
[view performSelector:selector withObject:anObject];
|
||||
|
||||
if (![view isKindOfClass:[self class]]) // Avoid infinite loop if a subview is a CPTableCellView.
|
||||
[self recursivelyPerformSelector:selector withObject:anObject startingFrom:view];
|
||||
}];
|
||||
}
|
||||
|
||||
- (CPString)description
|
||||
{
|
||||
return "<" + [self className] + " 0x" + [CPString stringWithHash:[self UID]] + " identifier=" + [self identifier] + ">";
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* CPTableView+Bindings.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
|
||||
|
||||
|
||||
@implementation CPTableView (Bindings)
|
||||
|
||||
+ (Class)_binderClassForBinding:(CPString)aBinding
|
||||
{
|
||||
if (aBinding == @"content")
|
||||
return [CPTableContentBinder class];
|
||||
|
||||
return [super _binderClassForBinding:aBinding];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (CPString)_replacementKeyPathForBinding:(CPString)aBinding
|
||||
{
|
||||
if (aBinding === @"selectionIndexes")
|
||||
return @"selectedRowIndexes";
|
||||
|
||||
return [super _replacementKeyPathForBinding:aBinding];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_establishBindingsIfUnbound:(id)destination
|
||||
{
|
||||
if ([[self infoForBinding:@"content"] objectForKey:CPObservedObjectKey] !== destination)
|
||||
{
|
||||
[super bind:@"content" toObject:destination withKeyPath:@"arrangedObjects" options:nil];
|
||||
_contentBindingExplicitlySet = NO;
|
||||
}
|
||||
|
||||
// If the content binding was set manually assume the user is taking manual control of establishing bindings.
|
||||
if (!_contentBindingExplicitlySet)
|
||||
{
|
||||
if ([[self infoForBinding:@"selectionIndexes"] objectForKey:CPObservedObjectKey] !== destination)
|
||||
[self bind:@"selectionIndexes" toObject:destination withKeyPath:@"selectionIndexes" options:nil];
|
||||
|
||||
if ([[self infoForBinding:@"sortDescriptors"] objectForKey:CPObservedObjectKey] !== destination)
|
||||
[self bind:@"sortDescriptors" toObject:destination withKeyPath:@"sortDescriptors" options:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)bind:(CPString)aBinding toObject:(id)anObject withKeyPath:(CPString)aKeyPath options:(CPDictionary)options
|
||||
{
|
||||
if (aBinding == @"content")
|
||||
_contentBindingExplicitlySet = YES;
|
||||
else if (aBinding == @"doubleClickTarget")
|
||||
{
|
||||
if ([options objectForKey:CPSelectorNameBindingOption])
|
||||
[self setDoubleAction:CPSelectorFromString([options objectForKey:CPSelectorNameBindingOption])];
|
||||
}
|
||||
|
||||
[super bind:aBinding toObject:anObject withKeyPath:aKeyPath options:options];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation CPTableContentBinder : CPBinder
|
||||
{
|
||||
id _content @accessors(property=content);
|
||||
}
|
||||
|
||||
- (void)setValueFor:(CPString)aBinding
|
||||
{
|
||||
var destination = [_info objectForKey:CPObservedObjectKey],
|
||||
keyPath = [_info objectForKey:CPObservedKeyPathKey];
|
||||
|
||||
_content = [destination valueForKey:keyPath];
|
||||
// FIXME: reload data for all rows or just exposed rows ?
|
||||
[_source _reloadDataViews];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* CPTableView+Coding.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
|
||||
|
||||
|
||||
|
||||
var CPTableViewDataSourceKey = @"CPTableViewDataSourceKey",
|
||||
CPTableViewDelegateKey = @"CPTableViewDelegateKey",
|
||||
CPTableViewHeaderViewKey = @"CPTableViewHeaderViewKey",
|
||||
CPTableViewTableColumnsKey = @"CPTableViewTableColumnsKey",
|
||||
CPTableViewRowHeightKey = @"CPTableViewRowHeightKey",
|
||||
CPTableViewIntercellSpacingKey = @"CPTableViewIntercellSpacingKey",
|
||||
CPTableViewSelectionHighlightStyleKey = @"CPTableViewSelectionHighlightStyleKey",
|
||||
CPTableViewMultipleSelectionKey = @"CPTableViewMultipleSelectionKey",
|
||||
CPTableViewEmptySelectionKey = @"CPTableViewEmptySelectionKey",
|
||||
CPTableViewColumnReorderingKey = @"CPTableViewColumnReorderingKey",
|
||||
CPTableViewColumnResizingKey = @"CPTableViewColumnResizingKey",
|
||||
CPTableViewColumnSelectionKey = @"CPTableViewColumnSelectionKey",
|
||||
CPTableViewColumnAutoresizingStyleKey = @"CPTableViewColumnAutoresizingStyleKey",
|
||||
CPTableViewGridColorKey = @"CPTableViewGridColorKey",
|
||||
CPTableViewGridStyleMaskKey = @"CPTableViewGridStyleMaskKey",
|
||||
CPTableViewUsesAlternatingBackgroundKey = @"CPTableViewUsesAlternatingBackgroundKey",
|
||||
CPTableViewAlternatingRowColorsKey = @"CPTableViewAlternatingRowColorsKey",
|
||||
CPTableViewCornerViewKey = @"CPTableViewCornerViewKey",
|
||||
CPTableViewAutosaveNameKey = @"CPTableViewAutosaveNameKey",
|
||||
CPTableViewArchivedReusableViewsKey = @"CPTableViewArchivedReusableViewsKey";
|
||||
|
||||
@implementation CPTableView (CPCoding)
|
||||
|
||||
- (id)initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
self = [super initWithCoder:aCoder];
|
||||
|
||||
if (self)
|
||||
{
|
||||
//Configuring Behavior
|
||||
_allowsColumnReordering = [aCoder decodeBoolForKey:CPTableViewColumnReorderingKey];
|
||||
_allowsColumnResizing = [aCoder decodeBoolForKey:CPTableViewColumnResizingKey];
|
||||
_allowsMultipleSelection = [aCoder decodeBoolForKey:CPTableViewMultipleSelectionKey];
|
||||
_allowsEmptySelection = [aCoder decodeBoolForKey:CPTableViewEmptySelectionKey];
|
||||
_allowsColumnSelection = [aCoder decodeBoolForKey:CPTableViewColumnSelectionKey];
|
||||
|
||||
//Setting Display Attributes
|
||||
_selectionHighlightStyle = [aCoder decodeIntForKey:CPTableViewSelectionHighlightStyleKey];
|
||||
_columnAutoResizingStyle = [aCoder decodeIntForKey:CPTableViewColumnAutoresizingStyleKey];
|
||||
|
||||
_tableColumns = [aCoder decodeObjectForKey:CPTableViewTableColumnsKey] || [];
|
||||
[_tableColumns makeObjectsPerformSelector:@selector(setTableView:) withObject:self];
|
||||
|
||||
_rowHeight = [aCoder decodeFloatForKey:CPTableViewRowHeightKey] || [self valueForThemeAttribute:@"default-row-height"];
|
||||
_intercellSpacing = [aCoder decodeSizeForKey:CPTableViewIntercellSpacingKey];
|
||||
|
||||
if (CGSizeEqualToSize(_intercellSpacing, CGSizeMakeZero()))
|
||||
_intercellSpacing = CGSizeMake(3.0, 2.0);
|
||||
|
||||
[self setGridColor:[aCoder decodeObjectForKey:CPTableViewGridColorKey]];
|
||||
_gridStyleMask = [aCoder decodeIntForKey:CPTableViewGridStyleMaskKey];
|
||||
|
||||
_usesAlternatingRowBackgroundColors = [aCoder decodeObjectForKey:CPTableViewUsesAlternatingBackgroundKey];
|
||||
[self setAlternatingRowBackgroundColors:[aCoder decodeObjectForKey:CPTableViewAlternatingRowColorsKey]];
|
||||
|
||||
_headerView = [aCoder decodeObjectForKey:CPTableViewHeaderViewKey];
|
||||
_cornerView = [aCoder decodeObjectForKey:CPTableViewCornerViewKey];
|
||||
|
||||
[self _init];
|
||||
|
||||
if ([aCoder containsValueForKey:CPTableViewArchivedReusableViewsKey])
|
||||
_archivedDataViews = [aCoder decodeObjectForKey:CPTableViewArchivedReusableViewsKey];
|
||||
|
||||
// Setting the data source reloads the table, which needs the state set by _init.
|
||||
[self setDataSource:[aCoder decodeObjectForKey:CPTableViewDataSourceKey]];
|
||||
[self setDelegate:[aCoder decodeObjectForKey:CPTableViewDelegateKey]];
|
||||
|
||||
[self _updateIsViewBased];
|
||||
|
||||
[self viewWillMoveToSuperview:[self superview]];
|
||||
|
||||
// Do this as late as possible to make sure the tableview is fully configured
|
||||
[self setAutosaveName:[aCoder decodeObjectForKey:CPTableViewAutosaveNameKey]];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
[super encodeWithCoder:aCoder];
|
||||
|
||||
[aCoder encodeObject:_dataSource forKey:CPTableViewDataSourceKey];
|
||||
[aCoder encodeObject:_delegate forKey:CPTableViewDelegateKey];
|
||||
|
||||
[aCoder encodeFloat:_rowHeight forKey:CPTableViewRowHeightKey];
|
||||
[aCoder encodeSize:_intercellSpacing forKey:CPTableViewIntercellSpacingKey];
|
||||
|
||||
[aCoder encodeInt:_selectionHighlightStyle forKey:CPTableViewSelectionHighlightStyleKey];
|
||||
[aCoder encodeInt:_columnAutoResizingStyle forKey:CPTableViewColumnAutoresizingStyleKey];
|
||||
|
||||
[aCoder encodeBool:_allowsMultipleSelection forKey:CPTableViewMultipleSelectionKey];
|
||||
[aCoder encodeBool:_allowsEmptySelection forKey:CPTableViewEmptySelectionKey];
|
||||
[aCoder encodeBool:_allowsColumnReordering forKey:CPTableViewColumnReorderingKey];
|
||||
[aCoder encodeBool:_allowsColumnResizing forKey:CPTableViewColumnResizingKey];
|
||||
[aCoder encodeBool:_allowsColumnSelection forKey:CPTableViewColumnSelectionKey];
|
||||
|
||||
[aCoder encodeObject:_tableColumns forKey:CPTableViewTableColumnsKey];
|
||||
|
||||
[aCoder encodeObject:[self gridColor] forKey:CPTableViewGridColorKey];
|
||||
[aCoder encodeInt:_gridStyleMask forKey:CPTableViewGridStyleMaskKey];
|
||||
|
||||
[aCoder encodeBool:_usesAlternatingRowBackgroundColors forKey:CPTableViewUsesAlternatingBackgroundKey];
|
||||
[aCoder encodeObject:[self alternatingRowBackgroundColors] forKey:CPTableViewAlternatingRowColorsKey];
|
||||
|
||||
[aCoder encodeObject:_cornerView forKey:CPTableViewCornerViewKey];
|
||||
[aCoder encodeObject:_headerView forKey:CPTableViewHeaderViewKey];
|
||||
|
||||
[aCoder encodeObject:_autosaveName forKey:CPTableViewAutosaveNameKey];
|
||||
|
||||
if (_archivedDataViews)
|
||||
[aCoder encodeObject:_archivedDataViews forKey:CPTableViewArchivedReusableViewsKey];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,642 @@
|
||||
/*
|
||||
* CPTableView+Columns.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
|
||||
|
||||
|
||||
@implementation CPTableView (Columns)
|
||||
|
||||
|
||||
//Column Management
|
||||
|
||||
/*!
|
||||
Adds a given column as the last column of the receiver.
|
||||
@param aColumn The column to add to the receiver.
|
||||
*/
|
||||
- (void)addTableColumn:(CPTableColumn)aTableColumn
|
||||
{
|
||||
[_tableColumns addObject:aTableColumn];
|
||||
[aTableColumn setTableView:self];
|
||||
|
||||
if (_dirtyTableColumnRangeIndex < 0)
|
||||
_dirtyTableColumnRangeIndex = [self _numberOfColumns] - 1;
|
||||
else
|
||||
_dirtyTableColumnRangeIndex = MIN([self _numberOfColumns] - 1, _dirtyTableColumnRangeIndex);
|
||||
|
||||
if ([[self sortDescriptors] count] > 0)
|
||||
{
|
||||
var mainSortDescriptor = [[self sortDescriptors] objectAtIndex:0];
|
||||
|
||||
if (aTableColumn === [self _tableColumnForSortDescriptor:mainSortDescriptor])
|
||||
{
|
||||
var image = [mainSortDescriptor ascending] ? [self _tableHeaderSortImage] : [self _tableHeaderReverseSortImage];
|
||||
[self setIndicatorImage:image inTableColumn:aTableColumn];
|
||||
}
|
||||
}
|
||||
|
||||
[self tile];
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
/*!
|
||||
Removes a given column from the receiver.
|
||||
@param aTableColumn The column to remove from the receiver.
|
||||
*/
|
||||
- (void)removeTableColumn:(CPTableColumn)aTableColumn
|
||||
{
|
||||
if ([aTableColumn tableView] !== self)
|
||||
return;
|
||||
|
||||
var index = [_tableColumns indexOfObjectIdenticalTo:aTableColumn];
|
||||
|
||||
if (index === CPNotFound)
|
||||
return;
|
||||
|
||||
// we defer the actual removal until the end of the runloop in order to keep a reference to the column.
|
||||
[_differedColumnDataToRemove addObject:{"column":aTableColumn, "shouldBeHidden": [aTableColumn isHidden]}];
|
||||
_needsDifferedTableColumnRemove = YES;
|
||||
|
||||
[aTableColumn setHidden:YES];
|
||||
[aTableColumn setTableView:nil];
|
||||
|
||||
var tableColumnUID = [aTableColumn UID];
|
||||
|
||||
if (_objectValues[tableColumnUID])
|
||||
_objectValues[tableColumnUID] = nil;
|
||||
|
||||
if (_dirtyTableColumnRangeIndex < 0)
|
||||
_dirtyTableColumnRangeIndex = index;
|
||||
else
|
||||
_dirtyTableColumnRangeIndex = MIN(index, _dirtyTableColumnRangeIndex);
|
||||
|
||||
[self reloadData];
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Internally used to set a column that will be dragged
|
||||
*/
|
||||
- (void)_setDraggedColumn:(CPInteger)columnIndex
|
||||
{
|
||||
if (_draggedColumnIndex === columnIndex)
|
||||
return;
|
||||
|
||||
// If ending a column drag, reselect the column if it was selected before the drag
|
||||
if (columnIndex === -1 && _draggedColumnIsSelected)
|
||||
[_selectedColumnIndexes addIndex:_draggedColumnIndex];
|
||||
|
||||
_draggedColumnIndex = columnIndex;
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
Same as moveColumn:toColumn: but doesn't trigger an autosave
|
||||
*/
|
||||
- (void)_moveColumn:(unsigned)fromIndex toColumn:(unsigned)toIndex
|
||||
{
|
||||
// Convert parameters such as "0" to 0.
|
||||
fromIndex = +fromIndex;
|
||||
toIndex = +toIndex;
|
||||
|
||||
if (fromIndex === toIndex)
|
||||
return;
|
||||
|
||||
if (_dirtyTableColumnRangeIndex < 0)
|
||||
_dirtyTableColumnRangeIndex = MIN(fromIndex, toIndex);
|
||||
else
|
||||
_dirtyTableColumnRangeIndex = MIN(fromIndex, toIndex, _dirtyTableColumnRangeIndex);
|
||||
|
||||
var tableColumn = _tableColumns[fromIndex],
|
||||
selectedTableColumns = [_tableColumns objectsAtIndexes:_selectedColumnIndexes];
|
||||
|
||||
[_tableColumns removeObjectAtIndex:fromIndex];
|
||||
[_tableColumns insertObject:tableColumn atIndex:toIndex];
|
||||
|
||||
[[self headerView] setNeedsLayout];
|
||||
[[self headerView] setNeedsDisplay:YES];
|
||||
|
||||
var range = CPMakeRange(MIN(fromIndex, toIndex), ABS(fromIndex - toIndex) + 1),
|
||||
layoutColumnIndexes = [CPIndexSet indexSetWithIndexesInRange:range],
|
||||
selectedColumnIndexes = [CPIndexSet indexSet];
|
||||
|
||||
[_tableColumns enumerateObjectsUsingBlock:function(tableColumn, idx, stop)
|
||||
{
|
||||
if ([selectedTableColumns containsObjectIdenticalTo:tableColumn])
|
||||
[selectedColumnIndexes addIndex:idx];
|
||||
}];
|
||||
|
||||
if ([_selectedColumnIndexes containsIndex:fromIndex] || (_draggedColumnIndex === fromIndex && _draggedColumnIsSelected))
|
||||
[selectedColumnIndexes addIndex:toIndex];
|
||||
|
||||
if (_draggedColumnIndex !== -1)
|
||||
[layoutColumnIndexes removeIndex:toIndex];
|
||||
|
||||
[self _layoutViewsForRowIndexes:_exposedRows columnIndexes:layoutColumnIndexes];
|
||||
[self selectColumnIndexes:selectedColumnIndexes byExtendingSelection:NO];
|
||||
[self setNeedsDisplay:YES];
|
||||
|
||||
// Notify even if programmatically moving a column as in Cocoa.
|
||||
// TODO Only notify when a column drag operation ends, not each time a column reaches a new slot?
|
||||
[[CPNotificationCenter defaultCenter] postNotificationName:CPTableViewColumnDidMoveNotification
|
||||
object:self
|
||||
userInfo:@{ @"CPOldColumn": fromIndex, @"CPNewColumn": toIndex }];
|
||||
|
||||
if (_implementedDelegateMethods & CPTableViewDelegate_tableViewColumnDidMove_)
|
||||
[_delegate tableViewColumnDidMove:[[CPNotification alloc] initWithName:CPTableViewColumnDidMoveNotification object:self userInfo:@{ @"CPOldColumn": fromIndex, @"CPNewColumn": toIndex }]];
|
||||
}
|
||||
|
||||
/*!
|
||||
Moves the column and heading at a given index to a new given index.
|
||||
@param theColumnIndex The current index of the column to move.
|
||||
@param theToIndex The new index for the moved column.
|
||||
*/
|
||||
- (void)moveColumn:(CPInteger)theColumnIndex toColumn:(CPInteger)theToIndex
|
||||
{
|
||||
[self _moveColumn:theColumnIndex toColumn:theToIndex];
|
||||
[self _autosave];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Called when a table column changes visibility
|
||||
*/
|
||||
- (void)_tableColumnVisibilityDidChange:(CPTableColumn)aColumn
|
||||
{
|
||||
var columnIndex = [[self tableColumns] indexOfObjectIdenticalTo:aColumn];
|
||||
|
||||
if (_dirtyTableColumnRangeIndex < 0)
|
||||
_dirtyTableColumnRangeIndex = columnIndex;
|
||||
else
|
||||
_dirtyTableColumnRangeIndex = MIN(columnIndex, _dirtyTableColumnRangeIndex);
|
||||
|
||||
[[self headerView] setNeedsLayout];
|
||||
[[self headerView] setNeedsDisplay:YES];
|
||||
|
||||
var rowIndexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [self numberOfRows])];
|
||||
[self _layoutViewsForRowIndexes:rowIndexes columnIndexes:[CPIndexSet indexSetWithIndex:columnIndex]];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns an array of CPTableColumns of all the receiver's columns.
|
||||
*/
|
||||
- (CPArray)tableColumns
|
||||
{
|
||||
return _tableColumns;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the index of the column with the specified identifier
|
||||
|
||||
@param anIdentifier the string value of the tablecolumn identifier
|
||||
@return the index of the column
|
||||
*/
|
||||
- (CPInteger)columnWithIdentifier:(CPString)anIdentifier
|
||||
{
|
||||
var index = 0,
|
||||
count = [self _numberOfColumns];
|
||||
|
||||
for (; index < count; ++index)
|
||||
if ([_tableColumns[index] identifier] === anIdentifier)
|
||||
return index;
|
||||
|
||||
return CPNotFound;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the CPTableColumn object with the given identifier string.
|
||||
|
||||
@param anIdentifier the string value of the identifier
|
||||
@return a CPTableColumn object with the given identifier
|
||||
*/
|
||||
- (CPTableColumn)tableColumnWithIdentifier:(CPString)anIdentifier
|
||||
{
|
||||
var index = [self columnWithIdentifier:anIdentifier];
|
||||
|
||||
if (index === CPNotFound)
|
||||
return nil;
|
||||
|
||||
return _tableColumns[index];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_didResizeTableColumn:(CPTableColumn)theColumn oldWidth:(int)oldWidth
|
||||
{
|
||||
[self _autosave];
|
||||
|
||||
[[CPNotificationCenter defaultCenter]
|
||||
postNotificationName:CPTableViewColumnDidResizeNotification
|
||||
object:self
|
||||
userInfo:@{ @"CPTableColumn": theColumn, @"CPOldWidth": oldWidth }];
|
||||
|
||||
if (_implementedDelegateMethods & CPTableViewDelegate_tableViewColumnDidResize_)
|
||||
[_delegate tableViewColumnDidResize:[[CPNotification alloc] initWithName:CPTableViewColumnDidResizeNotification object:self userInfo:@{ @"CPTableColumn": theColumn, @"CPOldWidth": oldWidth }]];
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the column autoresizing style of the receiver to a given style.
|
||||
|
||||
@param aStyle the column autoresizing style for the receiver. Valid values are:
|
||||
<pre>
|
||||
CPTableViewNoColumnAutoresizing
|
||||
CPTableViewUniformColumnAutoresizingStyle
|
||||
CPTableViewLastColumnOnlyAutoresizingStyle
|
||||
CPTableViewFirstColumnOnlyAutoresizingStyle
|
||||
</pre>
|
||||
*/
|
||||
- (void)setColumnAutoresizingStyle:(unsigned)style
|
||||
{
|
||||
//FIX ME: CPTableViewSequentialColumnAutoresizingStyle and CPTableViewReverseSequentialColumnAutoresizingStyle are not yet implemented
|
||||
_columnAutoResizingStyle = style;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the column auto resizing style of the receiver.
|
||||
*/
|
||||
- (unsigned)columnAutoresizingStyle
|
||||
{
|
||||
return _columnAutoResizingStyle;
|
||||
}
|
||||
|
||||
/*!
|
||||
Resizes the last column if there's room so the receiver fits exactly within its enclosing clip view.
|
||||
*/
|
||||
- (void)sizeLastColumnToFit
|
||||
{
|
||||
_lastColumnShouldSnap = YES;
|
||||
|
||||
var superview = [self superview];
|
||||
|
||||
if (!superview)
|
||||
return;
|
||||
|
||||
var superviewSize = [superview bounds].size;
|
||||
|
||||
[self _updateColumnRangesIfNecessary];
|
||||
|
||||
var count = [self _numberOfColumns];
|
||||
|
||||
// Decrement the counter until we get to the last column that's not hidden
|
||||
while (count-- && [_tableColumns[count] isHidden]);
|
||||
|
||||
// If the last column exists
|
||||
if (count >= 0)
|
||||
{
|
||||
var columnToResize = _tableColumns[count],
|
||||
newSize = MAX(0.0, superviewSize.width - CGRectGetMinX([self rectOfColumn:count]) - _intercellSpacing.width);
|
||||
|
||||
[columnToResize _tryToResizeToWidth:newSize];
|
||||
}
|
||||
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
/*!
|
||||
Informs the receiver that the number of records in the datasource has changed.
|
||||
*/
|
||||
- (void)noteNumberOfRowsChanged
|
||||
{
|
||||
var oldNumberOfRows = _numberOfRows;
|
||||
|
||||
_numberOfRows = [self _numberOfRows];
|
||||
|
||||
_cachedRowHeights = [];
|
||||
|
||||
// this line serves two purposes
|
||||
// 1. it updates the _numberOfRows cache with the -numberOfRows call
|
||||
// 2. it updates the row height cache if needed
|
||||
[self _noteHeightOfRowsWithIndexesChanged:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, _numberOfRows)]];
|
||||
|
||||
// remove row indexes from the selection if they no longer exist
|
||||
var hangingSelections = oldNumberOfRows - _numberOfRows;
|
||||
|
||||
if (hangingSelections > 0)
|
||||
{
|
||||
var previousSelectionCount = [_selectedRowIndexes count];
|
||||
[_selectedRowIndexes removeIndexesInRange:CPMakeRange(_numberOfRows, hangingSelections)];
|
||||
|
||||
if (![_selectedRowIndexes containsIndex:[self selectedRow]])
|
||||
_lastSelectedRow = CPNotFound;
|
||||
|
||||
// For optimal performance, only send a notification if indices were actually removed.
|
||||
if (previousSelectionCount > [_selectedRowIndexes count])
|
||||
[self _noteSelectionDidChange];
|
||||
}
|
||||
|
||||
[self tile];
|
||||
}
|
||||
|
||||
/*
|
||||
Populates the row height cache if necessary.
|
||||
*/
|
||||
- (void)_populateRowHeightCacheIfNeeded
|
||||
{
|
||||
if ([self numberOfRows] !== _cachedRowHeights.length)
|
||||
[self noteHeightOfRowsWithIndexesChanged:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, _numberOfRows)]];
|
||||
}
|
||||
|
||||
/*!
|
||||
Informs the receiver that the rows specified in indexSet have changed height.
|
||||
|
||||
@param anIndexSet an index set containing the indexes of the rows which changed height
|
||||
*/
|
||||
- (void)_noteHeightOfRowsWithIndexesChanged:(CPIndexSet)anIndexSet
|
||||
{
|
||||
if (![self _hasVariableRowHeights])
|
||||
return;
|
||||
|
||||
// Update the height of the given rows by calling the delegate. Since the row height cache also contains
|
||||
// y coordinates, we have to update the y coordinates of all rows below the first valid row in the range.
|
||||
var i = [anIndexSet indexGreaterThanOrEqualToIndex:0];
|
||||
|
||||
if (i === CPNotFound)
|
||||
return;
|
||||
|
||||
var y = i < _cachedRowHeights.length ? _cachedRowHeights[i].y : 0;
|
||||
|
||||
for (var count = [self numberOfRows]; i < count; ++i)
|
||||
{
|
||||
var height;
|
||||
|
||||
if ([anIndexSet containsIndex:i])
|
||||
height = [self _sendDelegateHeightOfRow:i];
|
||||
else
|
||||
height = _cachedRowHeights[i].height || _rowHeight; // in case the cache entry is empty
|
||||
|
||||
_cachedRowHeights[i] = {y:y, height:height};
|
||||
y += height + _intercellSpacing.height;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the CPTableColumn object of the highlighted table column.
|
||||
*/
|
||||
- (CPTableColumn)highlightedTableColumn
|
||||
{
|
||||
return _currentHighlightedTableColumn;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the table column for which the header should be highlighted.
|
||||
*/
|
||||
- (void)setHighlightedTableColumn:(CPTableColumn)aTableColumn
|
||||
{
|
||||
if (_currentHighlightedTableColumn == aTableColumn)
|
||||
return;
|
||||
|
||||
if (_headerView)
|
||||
{
|
||||
if (_currentHighlightedTableColumn != nil)
|
||||
[[_currentHighlightedTableColumn headerView] unsetThemeState:CPThemeStateSelected];
|
||||
|
||||
if (aTableColumn != nil)
|
||||
[[aTableColumn headerView] setThemeState:CPThemeStateSelected];
|
||||
}
|
||||
|
||||
_currentHighlightedTableColumn = aTableColumn;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns whether the receiver allows dragging the rows at rowIndexes with a drag initiated at mousedDownPoint.
|
||||
|
||||
@param rowIndexes an index set of rows to be dragged
|
||||
@param aPoint the point at which the mouse was clicked.
|
||||
*/
|
||||
- (BOOL)canDragRowsWithIndexes:(CPIndexSet)rowIndexes atPoint:(CGPoint)mouseDownPoint
|
||||
{
|
||||
return [rowIndexes count] > 0 && [self numberOfRows] > 0 && [self numberOfColumns] > 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
Computes and returns an image to use for dragging. This method is invoked ONLY IF dragViewForRowsWithIndexes:tableColumns:event:offset: returns nil.
|
||||
|
||||
@param dragRows an index set with the dragged row indexes
|
||||
@param theTableColumns an array of the table columns which are being dragged
|
||||
@param dragEvent the event which initiated the drag
|
||||
@param offset a point at which to set the drag image to be offset from the cursor
|
||||
|
||||
@return CPImage an image to use for the drag feedback
|
||||
*/
|
||||
- (CPImage)dragImageForRowsWithIndexes:(CPIndexSet)dragRows tableColumns:(CPArray)theTableColumns event:(CPEvent)dragEvent offset:(CGPoint)dragImageOffset
|
||||
{
|
||||
return [self valueForThemeAttribute:@"image-generic-file"];
|
||||
}
|
||||
|
||||
/*!
|
||||
Computes and returns a view to use for dragging. By default this is a slightly transparent copy of the dataviews which are being dragged.
|
||||
You can override this in a subclass to show different dragging feedback. Additionally you can return nil from this method and implement:
|
||||
- (CPImage)dragImageForRowsWithIndexes:tableColumns:event:offset: - if you want to return a simple image.
|
||||
|
||||
@param dragRows an index set with the dragged row indexes
|
||||
@param theTableColumns an array of the table columns which are being dragged
|
||||
@param dragEvent the event which initiated the drag
|
||||
@param offset a point at which to set the drag image to be offset from the cursor
|
||||
|
||||
@return CPView a view used as the dragging feedback
|
||||
*/
|
||||
- (CPView)dragViewForRowsWithIndexes:(CPIndexSet)theDraggedRows tableColumns:(CPArray)theTableColumns event:(CPEvent)theDragEvent offset:(CGPoint)dragViewOffset
|
||||
{
|
||||
var firstRowFrame = [self frameOfDataViewAtColumn:0 row:[theDraggedRows firstIndex]],
|
||||
lastRowFrame = [self frameOfDataViewAtColumn:0 row:[theDraggedRows lastIndex]],
|
||||
dragViewHeight = CGRectGetMaxY(lastRowFrame) - CGRectGetMinY(firstRowFrame);
|
||||
|
||||
var bounds = CGRectMake(0, 0, CGRectGetWidth([self bounds]), dragViewHeight),
|
||||
dragView = [[CPView alloc] initWithFrame:bounds];
|
||||
|
||||
[dragView setAlphaValue:0.7];
|
||||
// [dragView setBackgroundColor:[CPColor colorWithWhite:1 alpha:0.5]];
|
||||
|
||||
// We have to fetch all the data views for the selected rows and columns
|
||||
// After that we can copy these add them to a transparent drag view and use that drag view
|
||||
// to make it appear we are dragging images of those rows (as you would do in regular Cocoa)
|
||||
[self _enumerateViewsInRows:theDraggedRows tableColumns:theTableColumns usingBlock:function(v, row, tableColumn, stop)
|
||||
{
|
||||
var column = [_tableColumns indexOfObjectIdenticalTo:tableColumn],
|
||||
newDataView = [self preparedViewAtColumn:column row:row],
|
||||
origin = [newDataView frame].origin;
|
||||
|
||||
origin.y -= CGRectGetMinY(firstRowFrame);
|
||||
[newDataView setFrameOrigin:origin];
|
||||
|
||||
[dragView addSubview:newDataView];
|
||||
}];
|
||||
|
||||
var dragPoint = [self convertPoint:[theDragEvent locationInWindow] fromView:nil];
|
||||
dragViewOffset.x = CGRectGetWidth(bounds) / 2 - dragPoint.x;
|
||||
dragViewOffset.y = CGRectGetHeight(bounds) / 2 - dragPoint.y;
|
||||
|
||||
return dragView;
|
||||
}
|
||||
|
||||
- (CPView)_animationViewForColumn:(CPInteger)columnIndex
|
||||
{
|
||||
return [self _makeGhostViewForColumn:columnIndex forDragging:NO];
|
||||
}
|
||||
|
||||
- (CPView)_dragViewForColumn:(CPInteger)columnIndex
|
||||
{
|
||||
return [self _makeGhostViewForColumn:columnIndex forDragging:YES];
|
||||
}
|
||||
|
||||
- (CPView)_makeGhostViewForColumn:(CPInteger)columnIndex forDragging:(BOOL)isForDragging
|
||||
{
|
||||
var headerFrame = [_headerView frame],
|
||||
visibleRect = [self visibleRect],
|
||||
visibleRows = [self rowsInRect:visibleRect],
|
||||
columnRect = [self rectOfColumn:columnIndex],
|
||||
tableColumn = [[self tableColumns] objectAtIndex:columnIndex],
|
||||
tableColumnUID = [tableColumn UID],
|
||||
columnHeaderView = [tableColumn headerView],
|
||||
columnHeaderFrame = [columnHeaderView frame],
|
||||
frame = CGRectMake(MAX(CGRectGetMinX(columnRect)/* - CGRectGetMinX(visibleRect)*/, 0.0),
|
||||
0.0,
|
||||
CGRectGetWidth(columnHeaderFrame),
|
||||
CGRectGetHeight(visibleRect) + CGRectGetHeight(headerFrame));
|
||||
|
||||
// We need a wrapper view around the header and column, this is what will be dragged
|
||||
var dragView = [[_CPColumnDragDrawingView alloc] initWithFrame:frame];
|
||||
|
||||
[dragView setTableView:self];
|
||||
[dragView setColumnIndex:columnIndex];
|
||||
[dragView setBackgroundColor:[CPColor clearColor]];
|
||||
[dragView setAlphaValue:(isForDragging ? 0.6 : 1.0)];
|
||||
[dragView setShouldDrawBorders:isForDragging];
|
||||
[dragView setIsSelected:[self isColumnSelected:columnIndex]];
|
||||
|
||||
// Now a view that clips the column data views, which itself is clipped to the content view
|
||||
var columnVisRect = CGRectIntersection(columnRect, visibleRect);
|
||||
|
||||
frame = CGRectMake(0.0, CGRectGetHeight(headerFrame), CGRectGetWidth(columnRect), CGRectGetHeight(columnVisRect));
|
||||
|
||||
var columnClipView = [[CPView alloc] initWithFrame:frame];
|
||||
|
||||
[dragView addSubview:columnClipView];
|
||||
[dragView setColumnClipView:columnClipView];
|
||||
|
||||
if (isForDragging)
|
||||
_draggedColumnIsSelected = [self isColumnSelected:columnIndex];
|
||||
|
||||
var columnLeft = CGRectGetMinX(columnRect),
|
||||
offset = CGPointMake(columnLeft, CGRectGetMinY(visibleRect));
|
||||
|
||||
[self _enumerateViewsInRows:_exposedRows columns:[CPIndexSet indexSetWithIndex:columnIndex] usingBlock:function(dataView, row, column, stop)
|
||||
{
|
||||
[self _addDraggedDataView:dataView toView:columnClipView forColumn:column row:row offset:offset];
|
||||
delete (_dataViewsForRows[row][tableColumnUID]);
|
||||
}];
|
||||
|
||||
// Add the column header view
|
||||
columnHeaderFrame.origin = CGPointMakeZero();
|
||||
|
||||
var dragColumnHeaderView = [[_CPTableColumnHeaderView alloc] initWithFrame:columnHeaderFrame],
|
||||
image = [columnHeaderView _indicatorImage];
|
||||
|
||||
[dragColumnHeaderView setStringValue:[columnHeaderView stringValue]];
|
||||
[dragColumnHeaderView setThemeState:[columnHeaderView themeState]];
|
||||
|
||||
// Explicitly force the selected state on the ghost header if the original column is selected
|
||||
if ([self isColumnSelected:columnIndex])
|
||||
[dragColumnHeaderView setThemeState:CPThemeStateSelected];
|
||||
|
||||
[dragColumnHeaderView _setIndicatorImage:image];
|
||||
|
||||
if (isForDragging)
|
||||
// Give it a tag so it can be found later
|
||||
[dragColumnHeaderView setTag:1];
|
||||
|
||||
[dragView addSubview:dragColumnHeaderView];
|
||||
|
||||
// While dragging, the column is deselected in the table view
|
||||
[_selectedColumnIndexes removeIndex:columnIndex];
|
||||
[self setNeedsDisplay:YES];
|
||||
|
||||
return dragView;
|
||||
}
|
||||
|
||||
- (void)_addDraggedDataView:(CPView)aDataView toView:(CPView)aSuperview forColumn:(CPInteger)column row:(CPInteger)row offset:(CGPoint)offset
|
||||
{
|
||||
var dataViewFrame = [self frameOfDataViewAtColumn:column row:row];
|
||||
|
||||
dataViewFrame.origin.x -= offset.x;
|
||||
// Offset by table header height - scroll position
|
||||
dataViewFrame.origin.y -= offset.y;
|
||||
|
||||
[aDataView setFrame:dataViewFrame];
|
||||
[aSuperview addSubview:aDataView];
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the default operation mask for the drag behavior of the table view.
|
||||
@note isLocal is not implemented.
|
||||
*/
|
||||
- (void)setDraggingSourceOperationMask:(CPDragOperation)mask forLocal:(BOOL)isLocal
|
||||
{
|
||||
//ignore local for the time being since only one capp app can run at a time...
|
||||
_dragOperationDefaultMask = mask;
|
||||
}
|
||||
|
||||
/*!
|
||||
This should be called inside tableView:validateDrop:... method
|
||||
either CPTableViewDropOn or CPTableViewDropAbove,
|
||||
Specify the row as -1 to select the whole table for drop on.
|
||||
*/
|
||||
- (void)setDropRow:(CPInteger)row dropOperation:(CPTableViewDropOperation)operation
|
||||
{
|
||||
if (row > [self numberOfRows] && operation === CPTableViewDropOn)
|
||||
{
|
||||
var numberOfRows = [self numberOfRows] + 1,
|
||||
reason = @"Attempt to set dropRow=" + row +
|
||||
" dropOperation=CPTableViewDropOn when [0 - " + numberOfRows + "] is valid range of rows.";
|
||||
|
||||
[[CPException exceptionWithName:@"Error" reason:reason userInfo:nil] raise];
|
||||
}
|
||||
|
||||
_retargetedDropRow = row;
|
||||
_retargetedDropOperation = operation;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation _CPColumnDragDrawingView : CPView
|
||||
{
|
||||
CPTableView tableView @accessors;
|
||||
int columnIndex @accessors;
|
||||
CPView columnClipView @accessors;
|
||||
BOOL shouldDrawBorders @accessors;
|
||||
BOOL isSelected @accessors;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* CPTableView+DataSource.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
|
||||
|
||||
|
||||
|
||||
@implementation CPTableView (TableViewDataSource)
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return YES if the dataSource implements tableView:objectValueForTableColumn:row
|
||||
*/
|
||||
- (BOOL)_dataSourceRespondsToObjectValueForTableColumn
|
||||
{
|
||||
return _implementedDataSourceMethods & CPTableViewDataSource_tableView_objectValueForTableColumn_row_;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return YES if the dataSource implements tableView:writeRowsWithIndexes:toPasteboard:
|
||||
*/
|
||||
- (BOOL)_dataSourceRespondsToWriteRowsWithIndexesToPasteboard
|
||||
{
|
||||
return _implementedDataSourceMethods & CPTableViewDataSource_tableView_writeRowsWithIndexes_toPasteboard_;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return YES if the dataSource implements tableView:setObjectValue:forTableColumn:row:
|
||||
*/
|
||||
- (BOOL)_dataSourceRespondsToSetObjectValueForTableColumnRow
|
||||
{
|
||||
return CPTableViewDataSource_tableView_setObjectValue_forTableColumn_row_;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return YES if the dataSource implements tableView:validateDrop:proposedRow:proposedDropOperation:;
|
||||
*/
|
||||
- (BOOL)_dataSourceRespondsToValidateDropProposedRowProposedDropOperation
|
||||
{
|
||||
return _implementedDataSourceMethods & CPTableViewDataSource_tableView_validateDrop_proposedRow_proposedDropOperation_;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return YES if the dataSource implements numberOfRowsInTableView
|
||||
*/
|
||||
- (BOOL)_dataSourceRespondsToNumberOfRowsinTableView
|
||||
{
|
||||
return _implementedDataSourceMethods & CPTableViewDataSource_numberOfRowsInTableView_;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return the number of rows of the tableView
|
||||
By default return 0.
|
||||
*/
|
||||
- (int)_sendDataSourceNumberOfRowsInTableView
|
||||
{
|
||||
if (!(_implementedDataSourceMethods & CPTableViewDataSource_numberOfRowsInTableView_))
|
||||
return 0;
|
||||
|
||||
return [_dataSource numberOfRowsInTableView:self];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return the objectValue for the given column and row.
|
||||
By default return nil.
|
||||
*/
|
||||
- (id)_sendDataSourceObjectValueForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDataSourceMethods & CPTableViewDataSource_tableView_objectValueForTableColumn_row_))
|
||||
return nil;
|
||||
|
||||
return [_dataSource tableView:self objectValueForTableColumn:aTableColumn row:aRowIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Call the method tableView:setObjectValue:ForTableColum:row: of the dataSource
|
||||
*/
|
||||
- (void)_sendDataSourceSetObjectValue:(id)anObject forTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDataSourceMethods & CPTableViewDataSource_tableView_setObjectValue_forTableColumn_row_))
|
||||
return;
|
||||
|
||||
[_dataSource tableView:self setObjectValue:anObject forTableColumn:aTableColumn row:aRowIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Call the method tableView:sortDescriptorsDidChange: of the dataSource
|
||||
*/
|
||||
- (void)_sendDataSourceSortDescriptorsDidChange:(CPArray)descriptors
|
||||
{
|
||||
if (!(_implementedDataSourceMethods & CPTableViewDataSource_tableView_sortDescriptorsDidChange_))
|
||||
return;
|
||||
|
||||
[_dataSource tableView:self sortDescriptorsDidChange:descriptors];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return if the drop is accepted or not for the given dropOperation, info and row. By default return NO.
|
||||
*/
|
||||
- (BOOL)_sendDataSourceAcceptDrop:(id)info row:(CPInteger)aRowIndex dropOperation:(CPTableViewDropOperation)operation
|
||||
{
|
||||
if (!(_implementedDataSourceMethods & CPTableViewDataSource_tableView_acceptDrop_row_dropOperation_))
|
||||
return NO;
|
||||
|
||||
return [_dataSource tableView:self acceptDrop:info row:aRowIndex dropOperation:operation];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return the dragOperation for the given row and dropOperation. By default return CPDragOperationNone.
|
||||
*/
|
||||
- (CPDragOperation)_sendDataSourceValidateDrop:(id)info proposedRow:(CPInteger)aRowIndex proposedDropOperation:(CPTableViewDropOperation)operation
|
||||
{
|
||||
if (!(_implementedDataSourceMethods & CPTableViewDataSource_tableView_validateDrop_proposedRow_proposedDropOperation_))
|
||||
return CPDragOperationNone;
|
||||
|
||||
return [_dataSource tableView:self validateDrop:info proposedRow:aRowIndex proposedDropOperation:operation];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return a boolean for writeRowsWithIndexes:toPasteroard for the given pasteboard and row. By default return NO
|
||||
*/
|
||||
- (BOOL)_sendDataSourceWriteRowsWithIndexes:(CPIndexSet)rowIndexes toPasteboard:(CPPasteboard)pboard
|
||||
{
|
||||
if (!(_implementedDataSourceMethods & CPTableViewDataSource_tableView_writeRowsWithIndexes_toPasteboard_))
|
||||
return NO;
|
||||
|
||||
return [_dataSource tableView:self writeRowsWithIndexes:rowIndexes toPasteboard:pboard];
|
||||
}
|
||||
|
||||
/*
|
||||
This method is sent to the data source for convenience...
|
||||
*/
|
||||
- (void)draggedImage:(CPImage)anImage endedAt:(CGPoint)aLocation operation:(CPDragOperation)anOperation
|
||||
{
|
||||
if ([_dataSource respondsToSelector:@selector(tableView:didEndDraggedImage:atPosition:operation:)])
|
||||
[_dataSource tableView:self didEndDraggedImage:anImage atPosition:aLocation operation:anOperation];
|
||||
}
|
||||
|
||||
|
||||
// MARK: -
|
||||
// MARK: DataSource methods to implement
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Not yet implemented
|
||||
*/
|
||||
- (CPArray)_sendDataSourceNamesOfPromisedFilesDroppedAtDestination:(CPURL)dropDestination forDraggedRowsWithIndexes:(CPIndexSet)indexSet
|
||||
{
|
||||
if (!(_implementedDataSourceMethods & CPTableViewDataSource_tableView_namesOfPromisedFilesDroppedAtDestination_forDraggedRowsWithIndexes_))
|
||||
return [];
|
||||
|
||||
return [_dataSource tableView:self namesOfPromisedFilesDroppedAtDestination:dropDestination forDraggedRowsWithIndexes:indexSet];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,375 @@
|
||||
/*
|
||||
* CPTableView+Delegate.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
|
||||
|
||||
|
||||
|
||||
@implementation CPTableView (TableViewDelegate)
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return YES if the delegate implements tableView:dataViewFortableColumn:row:
|
||||
*/
|
||||
- (BOOL)_delegateRespondsToDataViewForTableColumn
|
||||
{
|
||||
return _implementedDelegateMethods & CPTableViewDelegate_tableView_dataViewForTableColumn_row_;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return YES if the delegate implements tableView:viewFortableColumn:row:
|
||||
*/
|
||||
- (BOOL)_delegateRespondsToViewForTableColumn
|
||||
{
|
||||
return _implementedDelegateMethods & CPTableViewDelegate_tableView_viewForTableColumn_row_;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return YES if the delegate implements tableView:shouldSelectRow:
|
||||
*/
|
||||
- (BOOL)_delegateRespondsToShouldSelectRow
|
||||
{
|
||||
return _implementedDelegateMethods & CPTableViewDelegate_tableView_shouldSelectRow_;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return YES if the delegate implements tableView:selectionShouldChangeInTableView
|
||||
*/
|
||||
- (BOOL)_delegateRespondsToSelectionShouldChangeInTableView
|
||||
{
|
||||
return _implementedDelegateMethods & CPTableViewDelegate_selectionShouldChangeInTableView_;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return YES if the delegate implements tableView:selectionIndexesForProposedSelection
|
||||
*/
|
||||
- (BOOL)_delegateRespondsToSelectionIndexesForProposedSelection
|
||||
{
|
||||
return _implementedDelegateMethods & CPTableViewDelegate_tableView_selectionIndexesForProposedSelection_;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return YES if the delegate implements tableView:menuForTableColumn:row
|
||||
*/
|
||||
- (BOOL)_delegateRespondsToMenuForTableColumnRow
|
||||
{
|
||||
return _implementedDelegateMethods & CPTableViewDelegate_tableViewMenuForTableColumn_row_;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Call the delegate didClickTableColumn with the given tableColumn
|
||||
*/
|
||||
- (void)_sendDelegateDidClickTableColumn:(CPInteger)column
|
||||
{
|
||||
if (_implementedDelegateMethods & CPTableViewDelegate_tableView_didClickTableColumn_)
|
||||
[_delegate tableView:self didClickTableColumn:_tableColumns[column]];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Call the delegate didDragTableColumn with the given tableColumn
|
||||
*/
|
||||
- (void)_sendDelegateDidDragTableColumn:(CPTableColumn)aTableColumn
|
||||
{
|
||||
if (_implementedDelegateMethods & CPTableViewDelegate_tableView_didDragTableColumn_)
|
||||
[_delegate tableView:self didDragTableColumn:aTableColumn];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Call the delegate mouseDownInHeaderOfTableColumn with the given tableColumn
|
||||
*/
|
||||
- (void)_sendDelegateMouseDownInHeaderOfTableColumn:(CPInteger)column
|
||||
{
|
||||
if (_implementedDelegateMethods & CPTableViewDelegate_tableView_mouseDownInHeaderOfTableColumn_)
|
||||
[_delegate tableView:self mouseDownInHeaderOfTableColumn:_tableColumns[column]];
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
Call the delegate tableViewDeleteKeyPressed
|
||||
*/
|
||||
- (BOOL)_sendDelegateDeleteKeyPressed
|
||||
{
|
||||
if ([_delegate respondsToSelector: @selector(tableViewDeleteKeyPressed:)])
|
||||
{
|
||||
[_delegate tableViewDeleteKeyPressed:self];
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return if the selection should change. By default return YES
|
||||
*/
|
||||
- (BOOL)_sendDelegateSelectionShouldChangeInTableView
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_selectionShouldChangeInTableView_))
|
||||
return YES;
|
||||
|
||||
return [_delegate selectionShouldChangeInTableView:self];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return if the given row is a group or not. By default return NO.
|
||||
*/
|
||||
- (BOOL)_sendDelegateIsGroupRow:(CPInteger)anIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_isGroupRow_))
|
||||
return NO;
|
||||
|
||||
return [_delegate tableView:self isGroupRow:anIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return is we should select the given row. By Default return YES
|
||||
*/
|
||||
- (BOOL)_sendDelegateShouldSelectRow:(CPInteger)anIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_shouldSelectRow_))
|
||||
return YES;
|
||||
|
||||
return [_delegate tableView:self shouldSelectRow:anIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Call the delegate tableView:willDisplayView:forTableColumn:row:
|
||||
*/
|
||||
- (void)_sendDelegateWillDisplayView:(id)aCell forTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_willDisplayView_forTableColumn_row_))
|
||||
return;
|
||||
|
||||
[_delegate tableView:self willDisplayView:aCell forTableColumn:aTableColumn row:aRowIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Call the delegate tableView:willRemoveView:forTableColumn:row:
|
||||
*/
|
||||
- (void)_sendDelegateWillRemoveView:(id)aCell forTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_willRemoveView_forTableColumn_row_))
|
||||
return;
|
||||
|
||||
[_delegate tableView:self willRemoveView:aCell forTableColumn:aTableColumn row:aRowIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return a CPMenu for the given tableColumn and row. By default return the menu of super.
|
||||
*/
|
||||
- (CPMenu)_sendDelegateMenuForTableColumn:(CPTableColumn)aTableColumn row:aRowIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableViewMenuForTableColumn_row_))
|
||||
return nil;
|
||||
|
||||
return [_delegate tableView:self menuForTableColumn:aTableColumn row:aRowIndex];
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
Returns YES if the column at columnIndex can be reordered.
|
||||
It can be possible if column reordering is allowed and if the table view
|
||||
delegate also accept the reordering
|
||||
*/
|
||||
- (BOOL)_sendDelegateShouldReorderColumn:(CPInteger)columnIndex toColumn:(CPInteger)newColumnIndex
|
||||
{
|
||||
if ([self allowsColumnReordering] &&
|
||||
_implementedDelegateMethods & CPTableViewDelegate_tableView_shouldReorderColumn_toColumn_)
|
||||
{
|
||||
return [_delegate tableView:self shouldReorderColumn:columnIndex toColumn:newColumnIndex];
|
||||
}
|
||||
|
||||
return [self allowsColumnReordering];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return the height of the given row. By default return [self rowHeight].
|
||||
*/
|
||||
- (float)_sendDelegateHeightOfRow:(CPInteger)anIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_heightOfRow_))
|
||||
return [self rowHeight];
|
||||
|
||||
return [_delegate tableView:self heightOfRow:anIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return a boolean to know if we should or not edit the given row. By default return YES.
|
||||
*/
|
||||
- (BOOL)_sendDelegateShouldEditTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_shouldEditTableColumn_row_))
|
||||
return YES;
|
||||
|
||||
return [_delegate tableView:self shouldEditTableColumn:aTableColumn row:aRowIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return a new CPIndexSet instead of the proposedSelection. By default return the proposedSelection.
|
||||
*/
|
||||
- (CPIndexSet)_sendDelegateSelectionIndexesForProposedSelection:(CPIndexSet)anIndexSet
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_selectionIndexesForProposedSelection_))
|
||||
return anIndexSet;
|
||||
|
||||
return [_delegate tableView:self selectionIndexesForProposedSelection:anIndexSet];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return a view for the given tableColumn and row. By default return nil.
|
||||
*/
|
||||
- (CPView)_sendDelegateViewForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_viewForTableColumn_row_))
|
||||
return nil;
|
||||
|
||||
return [_delegate tableView:self viewForTableColumn:aTableColumn row:aRowIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Return a view for the given tableColumn and row. By default return nil.
|
||||
*/
|
||||
- (CPView)_sendDelegateDataViewForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_dataViewForTableColumn_row_))
|
||||
return nil;
|
||||
|
||||
return [_delegate tableView:self dataViewForTableColumn:aTableColumn row:aRowIndex];
|
||||
}
|
||||
|
||||
|
||||
// MARK: -
|
||||
// MARK: Delegate methods to implement
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Not yet implemented !
|
||||
*/
|
||||
- (BOOL)_sendDelegateShouldSelectTableColumn:(CPTableColumn)aTableColumn
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_shouldSelectTableColumn_))
|
||||
return YES;
|
||||
|
||||
return [_delegate tableView:self shouldSelectTableColumn:aTableColumn];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (CPString)_sendDelegateToolTipForView:(id)aView rect:(CGRect)aRect tableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex mouseLocation:(CGPoint)aPoint
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_toolTipForView_rect_tableColumn_row_mouseLocation_))
|
||||
return nil;
|
||||
|
||||
return [_delegate tableView:self toolTipForView:aView rect:aRect tableColumn:aTableColumn row:aRowIndex mouseLocation:aPoint];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Not yet implemented
|
||||
*/
|
||||
- (BOOL)_sendDelegateShouldTrackView:(id)aView forTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_shouldTrackView_forTableColumn_row_))
|
||||
return YES;
|
||||
|
||||
return [_delegate tableView:self shouldTrackView:aView forTableColumn:aTableColumn row:aRowIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Not yet implemented
|
||||
*/
|
||||
- (BOOL)_sendDelegateShouldShowViewExpansionForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_shouldShowViewExpansionForTableColumn_row_))
|
||||
return YES;
|
||||
|
||||
return [_delegate tableView:self shouldShowViewExpansionForTableColumn:aTableColumn row:aRowIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Not yet implemented
|
||||
*/
|
||||
- (BOOL)_sendDelegateShouldTypeSelectForEvent:(CPEvent)anEvent withCurrentSearchString:(CPString)aString
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_shouldTypeSelectForEvent_withCurrentSearchString_))
|
||||
return NO;
|
||||
|
||||
return [_delegate tableView:self shouldTypeSelectForEvent:anEvent withCurrentSearchString:aString];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Not yet implemented
|
||||
*/
|
||||
- (CPString)_sendDelegateTypeSelectStringForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_typeSelectStringForTableColumn_row_))
|
||||
return nil;
|
||||
|
||||
return [_delegate tableView:self typeSelectStringForTableColumn:aTableColumn row:aRowIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Not yet implemented !
|
||||
*/
|
||||
- (int)_sendDelegateNextTypeSelectMatchFromRow:(CPInteger)aRowIndex toRow:(CPInteger)aSecondRowIndex forString:(CPString)aString
|
||||
{
|
||||
if (!(_implementedDelegateMethods & CPTableViewDelegate_tableView_nextTypeSelectMatchFromRow_toRow_forString_))
|
||||
return -1;
|
||||
|
||||
return [_delegate tableView:self nextTypeSelectMatchFromRow:aRowIndex toRow:aSecondRowIndex forString:aString];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,424 @@
|
||||
/*
|
||||
* CPTableView+Dragging.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
|
||||
|
||||
|
||||
@implementation CPTableView (Dragging)
|
||||
|
||||
|
||||
/*
|
||||
@ignore
|
||||
*/
|
||||
- (CPTableViewDropOperation)_proposedDropOperationAtPoint:(CGPoint)theDragPoint
|
||||
{
|
||||
if (_retargetedDropOperation != nil)
|
||||
return _retargetedDropOperation;
|
||||
|
||||
var row = [self _proposedRowAtPoint:theDragPoint],
|
||||
rowRect = [self rectOfRow:row];
|
||||
|
||||
// If there is no (the default) or too little inter-cell spacing we create some room for the CPTableViewDropAbove indicator
|
||||
// This probably doesn't work if the row height is smaller than or around 5.0
|
||||
if ([self intercellSpacing].height < 5.0)
|
||||
rowRect = CGRectInset(rowRect, 0.0, 5.0 - [self intercellSpacing].height);
|
||||
|
||||
// If the altered row rect contains the drag point we show the drop on
|
||||
// We don't show the drop on indicator if we are dragging below the last row
|
||||
// in that case we always want to show the drop above indicator
|
||||
if (CGRectContainsPoint(rowRect, theDragPoint) && row < _numberOfRows)
|
||||
return CPTableViewDropOn;
|
||||
|
||||
return CPTableViewDropAbove;
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
*/
|
||||
- (CPInteger)_proposedRowAtPoint:(CGPoint)dragPoint
|
||||
{
|
||||
var row = [self rowAtPoint:dragPoint],
|
||||
// Determine if the mouse is currently closer to this row or the row below it
|
||||
lowerRow = row + 1,
|
||||
rect = [self rectOfRow:row],
|
||||
bottomPoint = CGRectGetMaxY(rect),
|
||||
bottomThirty = bottomPoint - ((bottomPoint - CGRectGetMinY(rect)) * 0.3),
|
||||
numberOfRows = [self numberOfRows];
|
||||
|
||||
if (row < 0)
|
||||
row = (CGRectGetMaxY(rect) < dragPoint.y) ? numberOfRows : row;
|
||||
else if (dragPoint.y > MAX(bottomThirty, bottomPoint - 6))
|
||||
row = lowerRow;
|
||||
|
||||
row = MIN(numberOfRows, row);
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (CGRect)_rectForDropHighlightViewOnRow:(CPInteger)theRowIndex
|
||||
{
|
||||
if (theRowIndex >= [self numberOfRows])
|
||||
theRowIndex = [self numberOfRows] - 1;
|
||||
|
||||
return [self _rectOfRow:theRowIndex checkRange:NO];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (CGRect)_rectForDropHighlightViewBetweenUpperRow:(CPInteger)theUpperRowIndex andLowerRow:(CPInteger)theLowerRowIndex offset:(CGPoint)theOffset
|
||||
{
|
||||
if (theLowerRowIndex > [self numberOfRows])
|
||||
theLowerRowIndex = [self numberOfRows];
|
||||
|
||||
return [self _rectOfRow:theLowerRowIndex checkRange:NO];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (CPDragOperation)draggingUpdated:(id)sender
|
||||
{
|
||||
_retargetedDropRow = nil;
|
||||
_retargetedDropOperation = nil;
|
||||
|
||||
var location = [self convertPoint:[sender draggingLocation] fromView:nil],
|
||||
dropOperation = [self _proposedDropOperationAtPoint:location],
|
||||
numberOfRows = [self numberOfRows],
|
||||
row = [self _proposedRowAtPoint:location],
|
||||
dragOperation = [self _sendDataSourceValidateDrop:sender proposedRow:row proposedDropOperation:dropOperation];
|
||||
|
||||
if (_retargetedDropRow != nil)
|
||||
row = _retargetedDropRow;
|
||||
|
||||
if (_retargetedDropOperation != nil)
|
||||
dropOperation = _retargetedDropOperation;
|
||||
|
||||
if (dropOperation === CPTableViewDropOn && row >= numberOfRows)
|
||||
row = numberOfRows - 1;
|
||||
|
||||
var rect = CGRectMakeZero();
|
||||
|
||||
if (row === -1)
|
||||
rect = [self exposedRect];
|
||||
else if (dropOperation === CPTableViewDropAbove)
|
||||
rect = [self _rectForDropHighlightViewBetweenUpperRow:row - 1 andLowerRow:row offset:location];
|
||||
else
|
||||
rect = [self _rectForDropHighlightViewOnRow:row];
|
||||
|
||||
[_dropOperationFeedbackView setDropOperation:row !== -1 ? dropOperation : CPDragOperationNone];
|
||||
[_dropOperationFeedbackView setHidden:(dragOperation == CPDragOperationNone)];
|
||||
[_dropOperationFeedbackView setFrame:rect];
|
||||
[_dropOperationFeedbackView setCurrentRow:row];
|
||||
[self addSubview:_dropOperationFeedbackView];
|
||||
|
||||
return dragOperation;
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
*/
|
||||
- (BOOL)prepareForDragOperation:(id)sender
|
||||
{
|
||||
// FIX ME: is there anything else that needs to happen here?
|
||||
// actual validation is called in draggingUpdated:
|
||||
[_dropOperationFeedbackView removeFromSuperview];
|
||||
|
||||
return [self _dataSourceRespondsToValidateDropProposedRowProposedDropOperation];
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
*/
|
||||
- (BOOL)performDragOperation:(id)sender
|
||||
{
|
||||
var location = [self convertPoint:[sender draggingLocation] fromView:nil],
|
||||
operation = [self _proposedDropOperationAtPoint:location],
|
||||
row = _retargetedDropRow;
|
||||
|
||||
if (row == nil)
|
||||
row = [self _proposedRowAtPoint:location];
|
||||
|
||||
return [self _sendDataSourceAcceptDrop:sender row:row dropOperation:operation];
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
*/
|
||||
- (void)concludeDragOperation:(id)sender
|
||||
{
|
||||
[self _reloadDataViews];
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
We're using this because we drag views instead of images so we can get the rows themselves to actually drag.
|
||||
*/
|
||||
- (void)draggedView:(CPImage)aView endedAt:(CGPoint)aLocation operation:(CPDragOperation)anOperation
|
||||
{
|
||||
[self _draggingEnded];
|
||||
[self draggedImage:aView endedAt:aLocation operation:anOperation];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_updateSelectionWithMouseAtRow:(CPInteger)aRow
|
||||
{
|
||||
//check to make sure the row exists
|
||||
if (aRow < 0)
|
||||
return;
|
||||
|
||||
var newSelection,
|
||||
shouldExtendSelection = NO;
|
||||
|
||||
// If cmd/ctrl was held down XOR the old selection with the proposed selection
|
||||
if ([self mouseDownFlags] & (CPCommandKeyMask | CPControlKeyMask | CPAlternateKeyMask))
|
||||
{
|
||||
if ([_selectedRowIndexes containsIndex:aRow])
|
||||
{
|
||||
newSelection = [_selectedRowIndexes copy];
|
||||
|
||||
[newSelection removeIndex:aRow];
|
||||
}
|
||||
else if (_allowsMultipleSelection)
|
||||
{
|
||||
newSelection = [_selectedRowIndexes copy];
|
||||
|
||||
[newSelection addIndex:aRow];
|
||||
}
|
||||
else
|
||||
newSelection = [CPIndexSet indexSetWithIndex:aRow];
|
||||
}
|
||||
else if (_allowsMultipleSelection)
|
||||
{
|
||||
if (_selectionAnchorRow == CPNotFound)
|
||||
_selectionAnchorRow = [self numberOfRows] - 1;
|
||||
|
||||
newSelection = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(MIN(aRow, _selectionAnchorRow), ABS(aRow - _selectionAnchorRow) + 1)];
|
||||
shouldExtendSelection = [self mouseDownFlags] & CPShiftKeyMask &&
|
||||
((_lastSelectedRow == [_selectedRowIndexes lastIndex] && aRow > _lastSelectedRow) ||
|
||||
(_lastSelectedRow == [_selectedRowIndexes firstIndex] && aRow < _lastSelectedRow));
|
||||
}
|
||||
else if (aRow >= 0 && aRow < _numberOfRows)
|
||||
newSelection = [CPIndexSet indexSetWithIndex:aRow];
|
||||
else
|
||||
newSelection = [CPIndexSet indexSet];
|
||||
|
||||
if ([newSelection isEqualToIndexSet:_selectedRowIndexes] && [_selectedColumnIndexes count] === 0)
|
||||
return;
|
||||
|
||||
if (![self _sendDelegateSelectionShouldChangeInTableView])
|
||||
return;
|
||||
|
||||
newSelection = [self _sendDelegateSelectionIndexesForProposedSelection:newSelection];
|
||||
|
||||
if (![self _delegateRespondsToSelectionIndexesForProposedSelection] && [self _delegateRespondsToShouldSelectRow])
|
||||
{
|
||||
var indexArray = [];
|
||||
|
||||
[newSelection getIndexes:indexArray maxCount:-1 inIndexRange:nil];
|
||||
|
||||
var indexCount = indexArray.length;
|
||||
|
||||
while (indexCount--)
|
||||
{
|
||||
var index = indexArray[indexCount];
|
||||
|
||||
if (![self _sendDelegateShouldSelectRow:index])
|
||||
[newSelection removeIndex:index];
|
||||
}
|
||||
|
||||
// as per cocoa
|
||||
if ([newSelection count] === 0)
|
||||
return;
|
||||
}
|
||||
|
||||
// if empty selection is not allowed and the new selection has nothing selected, abort
|
||||
if (!_allowsEmptySelection && [newSelection count] === 0)
|
||||
return;
|
||||
|
||||
if ([newSelection isEqualToIndexSet:_selectedRowIndexes])
|
||||
return;
|
||||
|
||||
[self _noteSelectionIsChanging];
|
||||
[self selectRowIndexes:newSelection byExtendingSelection:shouldExtendSelection];
|
||||
|
||||
_lastSelectedRow = [newSelection containsIndex:aRow] ? aRow : [newSelection lastIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_noteSelectionIsChanging
|
||||
{
|
||||
[[CPNotificationCenter defaultCenter]
|
||||
postNotificationName:CPTableViewSelectionIsChangingNotification
|
||||
object:self
|
||||
userInfo:nil];
|
||||
|
||||
if (_implementedDelegateMethods & CPTableViewDelegate_tableViewSelectionIsChanging_)
|
||||
[_delegate tableViewSelectionIsChanging:[[CPNotification alloc] initWithName:CPTableViewSelectionIsChangingNotification object:self userInfo:nil]];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_noteSelectionDidChange
|
||||
{
|
||||
[[CPNotificationCenter defaultCenter]
|
||||
postNotificationName:CPTableViewSelectionDidChangeNotification
|
||||
object:self
|
||||
userInfo:nil];
|
||||
|
||||
if (_implementedDelegateMethods & CPTableViewDelegate_tableViewSelectionDidChange_)
|
||||
[_delegate tableViewSelectionDidChange:[[CPNotification alloc] initWithName:CPTableViewSelectionDidChangeNotification object:self userInfo:nil]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation _CPDropOperationDrawingView : CPView
|
||||
{
|
||||
unsigned dropOperation @accessors;
|
||||
CPTableView tableView @accessors;
|
||||
int currentRow @accessors;
|
||||
BOOL isBlinking @accessors;
|
||||
}
|
||||
|
||||
- (void)drawRect:(CGRect)aRect
|
||||
{
|
||||
if (tableView._destinationDragStyle === CPTableViewDraggingDestinationFeedbackStyleNone || isBlinking)
|
||||
return;
|
||||
|
||||
var context = [[CPGraphicsContext currentContext] graphicsPort],
|
||||
borderRadius,
|
||||
borderColor,
|
||||
borderWidth,
|
||||
backgroundColor;
|
||||
|
||||
if (currentRow === -1)
|
||||
{
|
||||
borderColor = [tableView valueForThemeAttribute:@"dropview-on-border-color"];
|
||||
borderWidth = [tableView valueForThemeAttribute:@"dropview-on-border-width"];
|
||||
|
||||
CGContextSetStrokeColor(context, borderColor);
|
||||
CGContextSetLineWidth(context, borderWidth);
|
||||
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
|
||||
[self setFrameOrigin:CGPointMake(_frame.origin.x, _frame.origin.y - 8)];
|
||||
|
||||
var selectedRows = [tableView selectedRowIndexes];
|
||||
|
||||
if ([selectedRows containsIndex:currentRow - 1] || [selectedRows containsIndex:currentRow])
|
||||
{
|
||||
borderColor = [tableView valueForThemeAttribute:@"dropview-above-selected-border-color"];
|
||||
borderWidth = [tableView valueForThemeAttribute:@"dropview-above-selected-border-width"];
|
||||
}
|
||||
else
|
||||
{
|
||||
borderColor = [tableView valueForThemeAttribute:@"dropview-above-border-color"];
|
||||
borderWidth = [tableView valueForThemeAttribute:@"dropview-above-border-width"];
|
||||
}
|
||||
|
||||
CGContextSetStrokeColor(context, borderColor);
|
||||
CGContextSetLineWidth(context, borderWidth);
|
||||
CGContextStrokeEllipseInRect(context, CGRectMake(aRect.origin.x + 4, aRect.origin.y + 4, 8, 8)); // circle
|
||||
|
||||
CGContextBeginPath(context);
|
||||
CGContextMoveToPoint(context, 10, aRect.origin.y + 8);
|
||||
CGContextAddLineToPoint(context, aRect.size.width - aRect.origin.y - 8, aRect.origin.y + 8);
|
||||
CGContextStrokePath(context);
|
||||
}
|
||||
}
|
||||
|
||||
- (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
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* CPTableView+Drawing.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
|
||||
|
||||
|
||||
@implementation CPTableView (Drawing)
|
||||
|
||||
|
||||
- (void)_updateSelectedColumnBackgrounds
|
||||
{
|
||||
if (!CPDOMAvailable)
|
||||
return;
|
||||
|
||||
// 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)
|
||||
{
|
||||
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 view = [[CPView alloc] initWithFrame:rect];
|
||||
[view setBackgroundColor:color];
|
||||
[view setHitTests:NO];
|
||||
|
||||
// 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:
|
||||
// _CPTableRowViews (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];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)setNeedsDisplay:(BOOL)aFlag
|
||||
{
|
||||
[super setNeedsDisplay:aFlag];
|
||||
|
||||
[[self headerView] setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)setNeedsLayout
|
||||
{
|
||||
[super setNeedsLayout];
|
||||
[[self headerView] setNeedsLayout];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (BOOL)_isFocused
|
||||
{
|
||||
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
|
||||
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
* CPTableView+Editing.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
|
||||
|
||||
|
||||
@implementation CPTableView (Editing)
|
||||
|
||||
|
||||
- (void)_resignFirstResponderWithoutSendingAction:(CPView)aView
|
||||
{
|
||||
var action = [self _disableActionIfExists:aView];
|
||||
|
||||
[[self window] makeFirstResponder:self];
|
||||
|
||||
if (action)
|
||||
[aView setAction:action];
|
||||
}
|
||||
|
||||
- (void)_resignEditedView
|
||||
{
|
||||
var view = [[self window] firstResponder];
|
||||
|
||||
if ([view respondsToSelector:@selector(selectText:)])
|
||||
[view selectText:nil];
|
||||
|
||||
if (!_isViewBased)
|
||||
{
|
||||
[self _unregisterForEndEditingNote:view];
|
||||
[self _setEditingState:NO forView:view];
|
||||
}
|
||||
|
||||
[self _resignFirstResponderWithoutSendingAction:view];
|
||||
}
|
||||
|
||||
- (SEL)_disableActionIfExists:(CPView)aView
|
||||
{
|
||||
// TODO: We disable action to prevent it from beeing sent twice when we resign the FR inside a textEndEditing notification.
|
||||
// Check if this is due to a bug in CPTextField.
|
||||
var action = nil;
|
||||
if ([aView respondsToSelector:@selector(action)] && (action = [aView action]))
|
||||
[aView setAction:nil];
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
The action for any dataview that supports editing. This will only be called when the value was changed.
|
||||
The table view becomes the first responder after user is done editing a dataview.
|
||||
*/
|
||||
- (void)_commitDataViewObjectValue:(id)aDataView forColumn:(CPInteger)column andRow:(CPInteger)row
|
||||
{
|
||||
var editingTableColumn = _tableColumns[column];
|
||||
|
||||
if (_implementedDataSourceMethods & CPTableViewDataSource_tableView_setObjectValue_forTableColumn_row_)
|
||||
[_dataSource tableView:self setObjectValue:[aDataView objectValue] forTableColumn:editingTableColumn row:row];
|
||||
|
||||
// Allow the column binding to do a reverse set. Note that we do this even if the data source method above
|
||||
// is implemented.
|
||||
[editingTableColumn _reverseSetDataView:aDataView forRow:row];
|
||||
|
||||
if (row !== CPNotFound && column !== CPNotFound)
|
||||
[self _reloadDataForRowIndexes:[CPIndexSet indexSetWithIndex:row] columnIndexes:[CPIndexSet indexSetWithIndex:column]];
|
||||
}
|
||||
|
||||
- (void)_setEditingState:(BOOL)editingState forView:(CPView)aView
|
||||
{
|
||||
if ([aView respondsToSelector:@selector(setEditable:)])
|
||||
[aView setEditable:editingState];
|
||||
|
||||
if ([aView respondsToSelector:@selector(setSelectable:)])
|
||||
[aView setSelectable:editingState];
|
||||
|
||||
if ([aView isKindOfClass:[CPTextField class]])
|
||||
[aView setBezeled:editingState];
|
||||
}
|
||||
|
||||
/*!
|
||||
Edits the dataview at a given row and column. This method is usually invoked automatically and should rarely be invoked directly
|
||||
The row at supplied rowIndex must be selected otherwise an exception is thrown.
|
||||
|
||||
@param columnIndex the index of the column to edit
|
||||
@param rowIndex the index of the row to edit
|
||||
@param theEvent the mouse event which triggers the edit, you can pass nil
|
||||
@param flag YES if the dataview text should be selected, otherwise NO. (NOT YET IMPLEMENTED)
|
||||
*/
|
||||
- (void)editColumn:(CPInteger)columnIndex row:(CPInteger)rowIndex withEvent:(CPEvent)theEvent select:(BOOL)flag
|
||||
{
|
||||
if (![self isRowSelected:rowIndex])
|
||||
[[CPException exceptionWithName:@"Error" reason:@"Attempt to edit row " + rowIndex + " when not selected." userInfo:nil] raise];
|
||||
|
||||
[self _reloadDataViewsSynchronously];
|
||||
[self scrollRowToVisible:rowIndex];
|
||||
[self scrollColumnToVisible:columnIndex];
|
||||
|
||||
// Force layout to update exposed rows/views after scrolling
|
||||
// This prevents the view from being unloaded/reloaded during the makeFirstResponder call
|
||||
[self layoutIfNeeded];
|
||||
|
||||
// TODO Do something with flag.
|
||||
|
||||
_editingRow = rowIndex;
|
||||
_editingColumn = columnIndex;
|
||||
|
||||
var editingTableColumnUID = [_tableColumns[_editingColumn] UID],
|
||||
editingView = _dataViewsForRows[_editingRow][editingTableColumnUID];
|
||||
|
||||
[self _setEditingState:YES forView:editingView];
|
||||
[[self window] makeFirstResponder:editingView];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(CPString)keyPath ofObject:(id)object change:(CPDictionary)change context:(void)context
|
||||
{
|
||||
if (context === "editing" && [object superview] === self)
|
||||
{
|
||||
[object removeObserver:self forKeyPath:keyPath];
|
||||
|
||||
var row,
|
||||
column;
|
||||
|
||||
[self getColumn:@ref(column) row:@ref(row) forView:object];
|
||||
[self _commitDataViewObjectValue:object forColumn:column andRow:row];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the column of the currently edited cell, or CPNotFound if none.
|
||||
*/
|
||||
- (CPInteger)editedColumn
|
||||
{
|
||||
return _editingColumn;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the row of the currently edited cell, or CPNotFound if none.
|
||||
*/
|
||||
- (CPInteger)editedRow
|
||||
{
|
||||
return _editingRow;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)keyDown:(CPEvent)anEvent
|
||||
{
|
||||
var character = [anEvent charactersIgnoringModifiers],
|
||||
modifierFlags = [anEvent modifierFlags];
|
||||
|
||||
// Check for the key events manually, as opposed to waiting for CPWindow to sent the actual action message
|
||||
// in _processKeyboardUIKey:, because we might not want to handle the arrow events.
|
||||
if (character === CPUpArrowFunctionKey || character === CPDownArrowFunctionKey)
|
||||
{
|
||||
// We're not interested in the arrow keys if there are no rows.
|
||||
// Technically we should also not be interested if we can't scroll,
|
||||
// but Cocoa doesn't handle that situation either.
|
||||
if ([self numberOfRows] !== 0)
|
||||
{
|
||||
[self _moveSelectionWithEvent:anEvent upward:(character === CPUpArrowFunctionKey)];
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (character === CPDeleteCharacter || character === CPDeleteFunctionKey)
|
||||
{
|
||||
// Don't call super if the delegate is interested in the delete key
|
||||
if ([self _sendDelegateDeleteKeyPressed])
|
||||
return;
|
||||
}
|
||||
|
||||
[super keyDown:anEvent];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Determines if the selection is broken. A broken selection
|
||||
is a non-continuous selection of rows.
|
||||
*/
|
||||
- (BOOL)_selectionIsBroken
|
||||
{
|
||||
return [self selectedRowIndexes]._ranges.length !== 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Selection behaviour depends on two things:
|
||||
_lastSelectedRow and the anchored selection (the last row selected by itself)
|
||||
*/
|
||||
- (void)_moveSelectionWithEvent:(CPEvent)theEvent upward:(BOOL)shouldGoUpward
|
||||
{
|
||||
if (![self _sendDelegateSelectionShouldChangeInTableView])
|
||||
return;
|
||||
|
||||
var selectedIndexes = [self selectedRowIndexes];
|
||||
|
||||
if ([selectedIndexes count] > 0)
|
||||
{
|
||||
var extend = (([theEvent modifierFlags] & CPShiftKeyMask) && _allowsMultipleSelection),
|
||||
i = [self selectedRow];
|
||||
|
||||
if ([self _selectionIsBroken])
|
||||
{
|
||||
while ([selectedIndexes containsIndex:i])
|
||||
{
|
||||
shouldGoUpward ? i-- : i++;
|
||||
}
|
||||
_wasSelectionBroken = true;
|
||||
}
|
||||
else if (_wasSelectionBroken && ((shouldGoUpward && i !== [selectedIndexes firstIndex]) || (!shouldGoUpward && i !== [selectedIndexes lastIndex])))
|
||||
{
|
||||
shouldGoUpward ? i = [selectedIndexes firstIndex] - 1 : i = [selectedIndexes lastIndex];
|
||||
_wasSelectionBroken = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
shouldGoUpward ? i-- : i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var extend = NO;
|
||||
//no rows are currently selected
|
||||
if ([self numberOfRows] > 0)
|
||||
var i = shouldGoUpward ? [self numberOfRows] - 1 : 0; // if we select upward select the last row, otherwise select the first row
|
||||
}
|
||||
|
||||
if (i >= [self numberOfRows] || i < 0)
|
||||
return;
|
||||
|
||||
if ([self _delegateRespondsToSelectionIndexesForProposedSelection] || [self _delegateRespondsToShouldSelectRow])
|
||||
{
|
||||
var shouldSelect = !![[self _cleanUpSelectionRowIndexes:[CPIndexSet indexSetWithIndex:i]] count];
|
||||
|
||||
/* If shouldSelect returns NO it means this row cannot be selected.
|
||||
The proper behaviour is to then try to see if the next/previous
|
||||
row(s) can be selected, until we hit the first one that can be.
|
||||
*/
|
||||
while (!shouldSelect && (i < [self numberOfRows] && i > 0))
|
||||
{
|
||||
shouldGoUpward ? --i : ++i; //check to see if the row can be selected. If it can't be then see if the next row can be selected.
|
||||
shouldSelect = !![[self _cleanUpSelectionRowIndexes:[CPIndexSet indexSetWithIndex:i]] count];
|
||||
}
|
||||
|
||||
if (!shouldSelect)
|
||||
return;
|
||||
}
|
||||
|
||||
// If we go upward and see that this row is already selected we should deselect the row below.
|
||||
if (extend && [selectedIndexes containsIndex:i])
|
||||
{
|
||||
// The row we're on is the last to be selected.
|
||||
var differedLastSelectedRow = i;
|
||||
|
||||
// no remove the one before/after it
|
||||
shouldGoUpward ? i++ : i--;
|
||||
|
||||
[selectedIndexes removeIndex:i];
|
||||
|
||||
//we're going to replace the selection
|
||||
extend = NO;
|
||||
}
|
||||
else if (extend)
|
||||
{
|
||||
if ([selectedIndexes containsIndex:i])
|
||||
{
|
||||
i = shouldGoUpward ? [selectedIndexes firstIndex] -1 : [selectedIndexes lastIndex] + 1;
|
||||
i = MIN(MAX(i, 0), [self numberOfRows] - 1);
|
||||
}
|
||||
|
||||
[selectedIndexes addIndex:i];
|
||||
var differedLastSelectedRow = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedIndexes = [CPIndexSet indexSetWithIndex:i];
|
||||
var differedLastSelectedRow = i;
|
||||
}
|
||||
|
||||
selectedIndexes = [self _sendDelegateSelectionIndexesForProposedSelection:selectedIndexes];
|
||||
|
||||
[self selectRowIndexes:selectedIndexes byExtendingSelection:extend];
|
||||
|
||||
// we differ because selectRowIndexes: does its own thing which would set the wrong index
|
||||
_lastSelectedRow = differedLastSelectedRow;
|
||||
|
||||
if (i !== CPNotFound)
|
||||
[self scrollRowToVisible:i];
|
||||
}
|
||||
|
||||
- (void)_updateDataViewsFocusState
|
||||
{
|
||||
var isFocused = [self _isFocused];
|
||||
|
||||
// enumerateAvailableViewsUsingBlock calls [self reloadData], which is destructive
|
||||
// during a focus change (causes editing session to reset).
|
||||
[self _enumerateViewsInRows:_exposedRows columns:_exposedColumns usingBlock:function(view, row, column, stop)
|
||||
{
|
||||
// Only selected rows need to toggle between White and Black text
|
||||
if ([self isRowSelected:row] || [self isColumnSelected:column])
|
||||
{
|
||||
if (isFocused)
|
||||
[view setThemeState:CPThemeStateFirstResponder];
|
||||
else
|
||||
[view unsetThemeState:CPThemeStateFirstResponder];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,656 @@
|
||||
/*
|
||||
* CPTableView+Layout.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
|
||||
|
||||
|
||||
@implementation CPTableView (Layout)
|
||||
|
||||
|
||||
/*!
|
||||
Returns a range of indices for the rows that lie wholly or partially within the vertical boundaries of a given rectangle.
|
||||
|
||||
@param aRect A rectangle in the coordinate system of the receiver.
|
||||
*/
|
||||
- (CPRange)rowsInRect:(CGRect)aRect
|
||||
{
|
||||
// Complexity:
|
||||
// O(1)
|
||||
|
||||
// If we have no rows, then we won't intersect anything.
|
||||
if (_numberOfRows <= 0)
|
||||
return CPMakeRange(0, 0);
|
||||
|
||||
var bounds = [self bounds];
|
||||
|
||||
// No rows if the rect doesn't even intersect us.
|
||||
if (!CGRectIntersectsRect(aRect, bounds))
|
||||
return CPMakeRange(0, 0);
|
||||
|
||||
var firstRow = [self rowAtPoint:aRect.origin];
|
||||
|
||||
// first row has to be undershot, because if not we wouldn't be intersecting.
|
||||
if (firstRow < 0)
|
||||
firstRow = 0;
|
||||
|
||||
var lastRow = [self rowAtPoint:CGPointMake(0.0, CGRectGetMaxY(aRect))];
|
||||
|
||||
// last row has to be overshot, because if not we wouldn't be intersecting.
|
||||
if (lastRow < 0)
|
||||
lastRow = _numberOfRows - 1;
|
||||
|
||||
if (firstRow > lastRow)
|
||||
return CPMakeRange(0, 0);
|
||||
|
||||
return CPMakeRange(firstRow, lastRow - firstRow + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
Return the range of rows that lie wholly or partially within aRect.
|
||||
If the bottom of the last real row is above the bottom of aRect,
|
||||
synthesized rows of the default height are added to fill aRect.
|
||||
*/
|
||||
- (CPRange)_exposedRowsInRect:(CGRect)aRect
|
||||
{
|
||||
var rowRange = [self rowsInRect:aRect],
|
||||
lastRealRow = CPMaxRange(rowRange) - 1,
|
||||
rectOfLastRealRow = [self _rectOfRow:lastRealRow checkRange:NO],
|
||||
bottomOfRealRows = CGRectGetMaxY(rectOfLastRealRow),
|
||||
rectBottom = CGRectGetMaxY(aRect);
|
||||
|
||||
// If the bottom of the last real row is at or below the bottom of aRect, we are done
|
||||
if (bottomOfRealRows >= rectBottom)
|
||||
return rowRange;
|
||||
|
||||
var numberOfSynthesizedRows = CEIL((rectBottom - bottomOfRealRows) / [self _fullRowHeight]);
|
||||
|
||||
rowRange.length += numberOfSynthesizedRows;
|
||||
|
||||
return rowRange;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the indexes of the receiver's columns that intersect the specified rectangle.
|
||||
|
||||
@param aRect a rectangle in the coordinate system of the receiver.
|
||||
*/
|
||||
- (CPIndexSet)columnIndexesInRect:(CGRect)aRect
|
||||
{
|
||||
// Complexity:
|
||||
// O(log numberOfColumns) if table view contains no hidden columns
|
||||
// O(numberOfColumns) if table view contains hidden columns
|
||||
|
||||
if ([self _numberOfColumns] === 0)
|
||||
return [CPIndexSet indexSet];
|
||||
|
||||
var column = MAX(0, [self columnAtPoint:CGPointMake(aRect.origin.x, 0.0)]),
|
||||
lastColumn = [self columnAtPoint:CGPointMake(CGRectGetMaxX(aRect), 0.0)];
|
||||
|
||||
if (lastColumn === CPNotFound)
|
||||
lastColumn = [self _numberOfColumns] - 1;
|
||||
|
||||
if (column > lastColumn || lastColumn < 0)
|
||||
return [CPIndexSet indexSet];
|
||||
|
||||
// Don't bother doing the expensive removal of hidden indexes if we have no hidden columns.
|
||||
if (_numberOfHiddenColumns <= 0)
|
||||
return [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(column, lastColumn - column + 1)];
|
||||
|
||||
var indexSet = [CPIndexSet indexSet];
|
||||
|
||||
for (; column <= lastColumn; ++column)
|
||||
{
|
||||
var tableColumn = _tableColumns[column];
|
||||
|
||||
if (![tableColumn isHidden])
|
||||
[indexSet addIndex:column];
|
||||
}
|
||||
|
||||
return indexSet;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the index of a column at a given point. If no column is there CPNotFound is returned.
|
||||
|
||||
@param aPoint a CGPoint
|
||||
*/
|
||||
- (CPInteger)columnAtPoint:(CGPoint)aPoint
|
||||
{
|
||||
// Complexity:
|
||||
// O(log numberOfColumns) if table view contains no hidden columns
|
||||
// O(numberOfColumns) if table view contains hidden columns
|
||||
|
||||
var bounds = [self bounds];
|
||||
|
||||
if (!CGRectContainsPoint(bounds, aPoint))
|
||||
return CPNotFound;
|
||||
|
||||
[self _updateColumnRangesIfNecessary];
|
||||
|
||||
var x = aPoint.x,
|
||||
low = 0,
|
||||
high = _tableColumnRanges.length - 1;
|
||||
|
||||
while (low <= high)
|
||||
{
|
||||
var middle = FLOOR(low + (high - low) / 2),
|
||||
range = _tableColumnRanges[middle];
|
||||
|
||||
if (x < range.location)
|
||||
high = middle - 1;
|
||||
|
||||
else if (x >= CPMaxRange(range))
|
||||
low = middle + 1;
|
||||
|
||||
else
|
||||
{
|
||||
var numberOfColumns = _tableColumnRanges.length;
|
||||
|
||||
while (middle < numberOfColumns && [_tableColumns[middle] isHidden])
|
||||
++middle;
|
||||
|
||||
if (middle < numberOfColumns)
|
||||
return middle;
|
||||
|
||||
return CPNotFound;
|
||||
}
|
||||
}
|
||||
|
||||
return CPNotFound;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the index of a row at a particular point. If no row exists at that point -1 is returned.
|
||||
|
||||
@param aPoint a CGPoint
|
||||
*/
|
||||
- (CPInteger)rowAtPoint:(CGPoint)aPoint
|
||||
{
|
||||
// Complexity:
|
||||
// O(1) for fixed height rows or point out of bounds
|
||||
// O(log numberOfRows) for variable height rows
|
||||
|
||||
// aPoint.x must be within our bounds
|
||||
var bounds = [self bounds];
|
||||
|
||||
if (aPoint.x < CGRectGetMinX(bounds) || aPoint.x >= CGRectGetMaxX(bounds))
|
||||
return -1;
|
||||
|
||||
// aPoint.x is in bounds, now we just have to check aPoint.y
|
||||
|
||||
if ([self _hasVariableRowHeights])
|
||||
{
|
||||
// First make sure aPoint.y is above the bottom of the last row, otherwise we might
|
||||
// search the (potentially large number of) rows for nothing.
|
||||
var heightInfo = [_cachedRowHeights lastObject];
|
||||
|
||||
if (!heightInfo || aPoint.y >= [self _rowBottomOfHeightInfo:heightInfo])
|
||||
return -1;
|
||||
|
||||
return [_cachedRowHeights indexOfObject:aPoint
|
||||
inSortedRange:nil
|
||||
options:0
|
||||
usingComparator:function(aPoint, heightInfo)
|
||||
{
|
||||
if (aPoint.y < heightInfo.y)
|
||||
return CPOrderedAscending;
|
||||
|
||||
if (aPoint.y > [self _rowBottomOfHeightInfo:heightInfo])
|
||||
return CPOrderedDescending;
|
||||
|
||||
return CPOrderedSame;
|
||||
}];
|
||||
}
|
||||
else
|
||||
{
|
||||
var row = FLOOR(aPoint.y / [self _fullRowHeight]);
|
||||
|
||||
return row >= _numberOfRows ? -1 : row;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
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.
|
||||
@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.
|
||||
*/
|
||||
- (CPInteger)rowForView:(CPView)aView
|
||||
{
|
||||
var row;
|
||||
|
||||
[self getColumn:nil row:@ref(row) forView:aView];
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the index of the column for the specified view.
|
||||
|
||||
@param view The view.
|
||||
@return The index of the column corresponding to the view. Returns -1 if the view is not a dataView, or a subview of a dataView.
|
||||
@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.
|
||||
*/
|
||||
- (CPInteger)columnForView:(CPView)aView
|
||||
{
|
||||
var column;
|
||||
|
||||
[self getColumn:@ref(column) row:nil forView:aView];
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)getColumn:(Function)columnRef row:(Function)rowRef forView:(CPView)aView
|
||||
{
|
||||
var columnResult = -1,
|
||||
rowResult = -1;
|
||||
|
||||
if (aView && [aView isKindOfClass:[CPView class]] && ![aView isKindOfClass:[CPTableView class]])
|
||||
{
|
||||
var cellView = aView,
|
||||
contentView = [[self window] contentView],
|
||||
found = NO,
|
||||
max_rec = 100;
|
||||
|
||||
while (max_rec--)
|
||||
{
|
||||
if (!cellView || cellView === contentView)
|
||||
{
|
||||
found = NO;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
var superview = [cellView superview];
|
||||
|
||||
if ([superview isKindOfClass:[CPTableView class]])
|
||||
{
|
||||
found = YES;
|
||||
break;
|
||||
}
|
||||
|
||||
cellView = superview;
|
||||
}
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
[self _enumerateViewsInRows:_exposedRows columns:_exposedColumns usingBlock:function(view, row, column, stop)
|
||||
{
|
||||
|
||||
if (view === cellView)
|
||||
{
|
||||
columnResult = column;
|
||||
rowResult = row;
|
||||
stop(YES);
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
if (columnRef)
|
||||
columnRef(columnResult);
|
||||
|
||||
if (rowRef)
|
||||
rowRef(rowResult);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns a rect for the dataview / cell at the column and row given.
|
||||
If the column or row index is greater than the number of columns or rows a CGZeroRect is returned
|
||||
|
||||
@param aColumn index of the column
|
||||
@param aRow index of the row
|
||||
*/
|
||||
- (CGRect)frameOfDataViewAtColumn:(CPInteger)aColumn row:(CPInteger)aRow
|
||||
{
|
||||
[self _updateColumnRangesIfNecessary];
|
||||
|
||||
if (aColumn > [self numberOfColumns] || aRow > [self numberOfRows])
|
||||
return CGRectMakeZero();
|
||||
|
||||
var tableColumnRange = _tableColumnRanges[aColumn],
|
||||
rectOfRow = [self rectOfRow:aRow],
|
||||
leftInset = FLOOR(_intercellSpacing.width / 2.0),
|
||||
topInset = FLOOR(_intercellSpacing.height / 2.0);
|
||||
|
||||
return CGRectMake(tableColumnRange.location + leftInset, CGRectGetMinY(rectOfRow) + topInset, tableColumnRange.length - _intercellSpacing.width, CGRectGetHeight(rectOfRow) - _intercellSpacing.height);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)resizeWithOldSuperviewSize:(CGSize)aSize
|
||||
{
|
||||
[super resizeWithOldSuperviewSize:aSize];
|
||||
|
||||
// Ensure all row views stretch to fill the new width
|
||||
[self _updateAllVisibleRowViewsFrames];
|
||||
|
||||
if (_disableAutomaticResizing)
|
||||
return;
|
||||
|
||||
var mask = _columnAutoResizingStyle;
|
||||
|
||||
// should we actually do some resizing?
|
||||
if (!_lastColumnShouldSnap)
|
||||
{
|
||||
// did the clip view intersect the old tablesize?
|
||||
var superview = [self superview];
|
||||
|
||||
if (!superview || ![superview isKindOfClass:[CPClipView class]])
|
||||
return;
|
||||
|
||||
var superviewWidth = [superview bounds].size.width,
|
||||
lastColumnMaxX = CGRectGetMaxX([self rectOfColumn:[self numberOfColumns] -1]);
|
||||
|
||||
// Fix me: this fires on the table setup at times
|
||||
if (lastColumnMaxX >= superviewWidth && lastColumnMaxX <= aSize.width || lastColumnMaxX <= superviewWidth && lastColumnMaxX >= aSize.width)
|
||||
_lastColumnShouldSnap = YES;
|
||||
else if (mask === CPTableViewUniformColumnAutoresizingStyle)
|
||||
return;
|
||||
}
|
||||
|
||||
if (mask === CPTableViewUniformColumnAutoresizingStyle)
|
||||
[self _resizeAllColumnUniformlyWithOldSize:aSize];
|
||||
else if (mask === CPTableViewLastColumnOnlyAutoresizingStyle)
|
||||
[self sizeLastColumnToFit];
|
||||
else if (mask === CPTableViewFirstColumnOnlyAutoresizingStyle)
|
||||
[self _autoResizeFirstColumn];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_autoResizeFirstColumn
|
||||
{
|
||||
var superview = [self superview];
|
||||
|
||||
if (!superview)
|
||||
return;
|
||||
|
||||
[self _updateColumnRangesIfNecessary];
|
||||
|
||||
var count = [self _numberOfColumns],
|
||||
columnToResize = nil,
|
||||
totalWidth = 0,
|
||||
i = 0;
|
||||
|
||||
for (; i < count; i++)
|
||||
{
|
||||
var column = _tableColumns[i];
|
||||
|
||||
if (![column isHidden])
|
||||
{
|
||||
if (!columnToResize)
|
||||
columnToResize = column;
|
||||
totalWidth += [column width] + _intercellSpacing.width;
|
||||
}
|
||||
}
|
||||
|
||||
// If there is a visible column
|
||||
if (columnToResize)
|
||||
{
|
||||
var superviewSize = [superview bounds].size,
|
||||
newWidth = superviewSize.width - totalWidth;
|
||||
|
||||
newWidth += [columnToResize width];
|
||||
[columnToResize _tryToResizeToWidth:newWidth];
|
||||
}
|
||||
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
FIX ME: this can be a lot faster
|
||||
*/
|
||||
- (void)_resizeAllColumnUniformlyWithOldSize:(CGSize)oldSize
|
||||
{
|
||||
// what we care about is the superview clip rect
|
||||
// FIX ME: if it's not in a scrollview this doesn't really work
|
||||
var superview = [self superview];
|
||||
|
||||
if (!superview || ![superview isKindOfClass:[CPClipView class]])
|
||||
return;
|
||||
|
||||
[self _updateColumnRangesIfNecessary];
|
||||
|
||||
var superviewWidth = [superview bounds].size.width,
|
||||
count = [self _numberOfColumns],
|
||||
resizableColumns = [CPIndexSet indexSet],
|
||||
remainingSpace = 0.0,
|
||||
i = 0;
|
||||
|
||||
// find resizable columns
|
||||
// FIX ME: we could cache resizableColumns after this loop and reuse it during the resize
|
||||
for (; i < count; i++)
|
||||
{
|
||||
var tableColumn = _tableColumns[i];
|
||||
if (![tableColumn isHidden] && ([tableColumn resizingMask] & CPTableColumnAutoresizingMask))
|
||||
[resizableColumns addIndex:i];
|
||||
}
|
||||
|
||||
var maxXofColumns = CGRectGetMaxX([self rectOfColumn:[resizableColumns lastIndex]]),
|
||||
remainingSpace = superviewWidth - maxXofColumns,
|
||||
resizeableColumnsCount = [resizableColumns count],
|
||||
proportionate = 0;
|
||||
|
||||
while (remainingSpace && resizeableColumnsCount)
|
||||
{
|
||||
// Divy out the space.
|
||||
proportionate += remainingSpace / resizeableColumnsCount;
|
||||
|
||||
// Reset the remaining space to 0
|
||||
remainingSpace = 0.0;
|
||||
|
||||
var index = CPNotFound;
|
||||
|
||||
while ((index = [resizableColumns indexGreaterThanIndex:index]) !== CPNotFound)
|
||||
{
|
||||
var item = _tableColumns[index],
|
||||
proposedWidth = [item width] + proportionate,
|
||||
resizeLeftovers = [item _tryToResizeToWidth:proposedWidth];
|
||||
|
||||
if (resizeLeftovers)
|
||||
{
|
||||
[resizableColumns removeIndex:index];
|
||||
|
||||
remainingSpace += resizeLeftovers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now that we've reached the end we know there are likely rounding errors
|
||||
// so we should size the last resized to fit
|
||||
|
||||
// find the last visisble column
|
||||
while (count--)
|
||||
{
|
||||
var hidden = [_tableColumns[count] isHidden];
|
||||
if (!hidden)
|
||||
break;
|
||||
}
|
||||
|
||||
// find the max x, but subtract a single pixel since the spacing isn't applicable here.
|
||||
if (count >= 0)
|
||||
{
|
||||
var item = _tableColumns[count],
|
||||
delta = superviewWidth - CGRectGetMaxX([self rectOfColumn:count]) - ([self intercellSpacing].width || 1),
|
||||
newSize = [item width] + delta;
|
||||
|
||||
[item _tryToResizeToWidth:newSize];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Informs the receiver that the rows specified in indexSet have changed height.
|
||||
|
||||
@param anIndexSet an index set containing the indexes of the rows which changed height
|
||||
*/
|
||||
- (void)noteHeightOfRowsWithIndexesChanged:(CPIndexSet)anIndexSet
|
||||
{
|
||||
[self _noteHeightOfRowsWithIndexesChanged:anIndexSet];
|
||||
[self _reloadDataViews];
|
||||
}
|
||||
|
||||
/*!
|
||||
Lays out the dataviews and resizes the tableview so that everything fits.
|
||||
*/
|
||||
- (void)tile
|
||||
{
|
||||
[self _updateColumnRangesIfNecessary];
|
||||
|
||||
var width = _tableColumnRanges.length > 0 ? CPMaxRange([_tableColumnRanges lastObject]) : 0.0,
|
||||
superview = [self superview],
|
||||
height = 0;
|
||||
|
||||
if (![self _hasVariableRowHeights])
|
||||
height = [self _fullRowHeight] * _numberOfRows;
|
||||
else if (_numberOfRows > 0)
|
||||
{
|
||||
[self _populateRowHeightCacheIfNeeded];
|
||||
|
||||
var heightInfo = _cachedRowHeights[_cachedRowHeights.length - 1];
|
||||
|
||||
height = [self _rowBottomOfHeightInfo:heightInfo];
|
||||
}
|
||||
|
||||
if ([superview isKindOfClass:[CPClipView class]])
|
||||
{
|
||||
var superviewSize = [superview bounds].size;
|
||||
|
||||
width = MAX(superviewSize.width, width);
|
||||
height = MAX(superviewSize.height, height);
|
||||
}
|
||||
|
||||
[self setFrameSize:CGSizeMake(width, height)];
|
||||
|
||||
[self _updateSelectedColumnBackgrounds];
|
||||
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
Scrolls the receiver vertically in an enclosing CPClipView so the row specified by rowIndex is visible.
|
||||
|
||||
@param aRowIndex the index of the row to scroll to.
|
||||
*/
|
||||
- (void)scrollRowToVisible:(int)rowIndex
|
||||
{
|
||||
var visible = [self visibleRect],
|
||||
rowRect = [self rectOfRow:rowIndex];
|
||||
|
||||
visible.origin.y = rowRect.origin.y;
|
||||
visible.size.height = rowRect.size.height;
|
||||
|
||||
[self scrollRectToVisible:visible];
|
||||
}
|
||||
|
||||
/*!
|
||||
Scrolls the receiver and header view horizontally in an enclosing CPClipView so the column specified by columnIndex is visible.
|
||||
|
||||
@param aColumnIndex the index of the column to scroll to.
|
||||
*/
|
||||
- (void)scrollColumnToVisible:(int)columnIndex
|
||||
{
|
||||
var visible = [self visibleRect],
|
||||
colRect = [self rectOfColumn:columnIndex];
|
||||
|
||||
visible.origin.x = colRect.origin.x;
|
||||
visible.size.width = colRect.size.width;
|
||||
|
||||
[self scrollRectToVisible:visible];
|
||||
[_headerView scrollRectToVisible:colRect];
|
||||
}
|
||||
|
||||
/*!
|
||||
Set the name under which the table information is automatically saved to theAutosaveName.
|
||||
The table information is saved separately for each user and for each application that user uses.
|
||||
@note Even though a table view has an autosave name, it may not be saving table information automatically.
|
||||
To set whether table information is being saved automatically, use \c setAutosaveTableColumns:
|
||||
*/
|
||||
- (void)setAutosaveName:(CPString)theAutosaveName
|
||||
{
|
||||
if (_autosaveName === theAutosaveName)
|
||||
return;
|
||||
|
||||
_autosaveName = theAutosaveName;
|
||||
|
||||
[self setAutosaveTableColumns:!!theAutosaveName];
|
||||
[self _restoreFromAutosave];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the autosave name of the tableview.
|
||||
*/
|
||||
- (CPString)autosaveName
|
||||
{
|
||||
return _autosaveName;
|
||||
}
|
||||
|
||||
- (int)_numberOfColumns
|
||||
{
|
||||
return _tableColumns.length;
|
||||
}
|
||||
|
||||
- (void)_updateColumnRangesIfNecessary
|
||||
{
|
||||
if (_dirtyTableColumnRangeIndex !== CPNotFound)
|
||||
[self _recalculateTableColumnRanges];
|
||||
}
|
||||
|
||||
- (CGFloat)_fullRowHeight
|
||||
{
|
||||
return (_rowHeight + _intercellSpacing.height);
|
||||
}
|
||||
|
||||
- (CGFloat)_rowBottomOfHeightInfo:(JSObject)heightInfo
|
||||
{
|
||||
return (heightInfo.y + heightInfo.height + _intercellSpacing.height);
|
||||
}
|
||||
|
||||
- (BOOL)_hasVariableRowHeights
|
||||
{
|
||||
return (_implementedDelegateMethods & CPTableViewDelegate_tableView_heightOfRow_);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* CPTableView+Responder.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
|
||||
|
||||
|
||||
@implementation CPTableView (Responder)
|
||||
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)becomeKeyWindow
|
||||
{
|
||||
[self _notifyViewDidBecomeFirstResponder];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)resignKeyWindow
|
||||
{
|
||||
[self _notifyViewDidResignFirstResponder];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (BOOL)acceptsFirstResponder
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (BOOL)needsPanelToBecomeKey
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (CPView)hitTest:(CGPoint)aPoint
|
||||
{
|
||||
var hit = [super hitTest:aPoint];
|
||||
|
||||
if ([[CPApp currentEvent] type] !== CPLeftMouseDown)
|
||||
return hit;
|
||||
|
||||
return [self _hitTest:hit];
|
||||
}
|
||||
|
||||
- (id)_hitTest:(CPView)aView
|
||||
{
|
||||
var column,
|
||||
row;
|
||||
|
||||
if ([aView acceptsFirstResponder])
|
||||
{
|
||||
[self getColumn:@ref(column) row:@ref(row) forView:aView];
|
||||
|
||||
if (![self isRowSelected:row])
|
||||
{
|
||||
if (_selectionHighlightStyle == CPTableViewSelectionHighlightStyleNone)
|
||||
return aView;
|
||||
|
||||
return self;
|
||||
}
|
||||
}
|
||||
else if (!_isViewBased && [aView isKindOfClass:[CPControl class]] && ![aView isKindOfClass:[CPTextField class]])
|
||||
[aView addObserver:self forKeyPath:@"objectValue" options:CPKeyValueObservingOptionOld | CPKeyValueObservingOptionNew context:"editing"];
|
||||
|
||||
return aView;
|
||||
}
|
||||
|
||||
- (void)_removeObservers
|
||||
{
|
||||
if (!_isObserving)
|
||||
return;
|
||||
|
||||
[self _stopObservingClipView];
|
||||
[super _removeObservers];
|
||||
}
|
||||
|
||||
- (void)_addObservers
|
||||
{
|
||||
if (_isObserving)
|
||||
return;
|
||||
|
||||
[self _startObservingClipView];
|
||||
[super _addObservers];
|
||||
}
|
||||
|
||||
/*!
|
||||
Called when the receiver is about to be moved to a new window.
|
||||
@param aWindow the window to which the receiver will be moved.
|
||||
*/
|
||||
- (void)viewWillMoveToWindow:(CPWindow)aWindow
|
||||
{
|
||||
[super viewWillMoveToWindow:aWindow];
|
||||
|
||||
[self _stopObservingFirstResponderForWindow:[self window]];
|
||||
|
||||
if (aWindow)
|
||||
[self _startObservingFirstResponderForWindow:aWindow];
|
||||
}
|
||||
|
||||
- (void)_startObservingClipView
|
||||
{
|
||||
if (!_observedClipView)
|
||||
return;
|
||||
|
||||
var defaultCenter = [CPNotificationCenter defaultCenter];
|
||||
|
||||
[_observedClipView setPostsFrameChangedNotifications:YES];
|
||||
[_observedClipView setPostsBoundsChangedNotifications:YES];
|
||||
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(superviewFrameChanged:)
|
||||
name:CPViewFrameDidChangeNotification
|
||||
object:_observedClipView];
|
||||
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(superviewBoundsChanged:)
|
||||
name:CPViewBoundsDidChangeNotification
|
||||
object:_observedClipView];
|
||||
}
|
||||
|
||||
- (void)_stopObservingClipView
|
||||
{
|
||||
if (!_observedClipView)
|
||||
return;
|
||||
|
||||
var defaultCenter = [CPNotificationCenter defaultCenter];
|
||||
|
||||
[defaultCenter removeObserver:self
|
||||
name:CPViewFrameDidChangeNotification
|
||||
object:_observedClipView];
|
||||
|
||||
[defaultCenter removeObserver:self
|
||||
name:CPViewBoundsDidChangeNotification
|
||||
object:_observedClipView];
|
||||
}
|
||||
|
||||
- (void)_startObservingFirstResponderForWindow:(CPWindow)aWindow
|
||||
{
|
||||
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(_firstResponderDidChange:) name:_CPWindowDidChangeFirstResponderNotification object:aWindow];
|
||||
}
|
||||
|
||||
- (void)_stopObservingFirstResponderForWindow:(CPWindow)aWindow
|
||||
{
|
||||
[[CPNotificationCenter defaultCenter] removeObserver:self name:_CPWindowDidChangeFirstResponderNotification object:aWindow];
|
||||
}
|
||||
|
||||
- (void)_firstResponderDidChange:(CPNotification)aNotification
|
||||
{
|
||||
var responder = [[self window] firstResponder],
|
||||
column,
|
||||
row;
|
||||
|
||||
[self getColumn:@ref(column) row:@ref(row) forView:responder];
|
||||
|
||||
_editingRow = row;
|
||||
_editingColumn = column;
|
||||
|
||||
// We want to keep the 'First Responder' theme state for the table view as a whole, even when a subview is being edited.
|
||||
// This makes sure the theming effects of a focused table remain in effect even as cells are being edited in it.
|
||||
// Check if the firstResponder is outside the tableview:
|
||||
if (responder !== self && _editingRow == CPNotFound && _editingColumn == CPNotFound)
|
||||
[self _notifyViewDidResignFirstResponder];
|
||||
else
|
||||
[self _notifyViewDidBecomeFirstResponder];
|
||||
|
||||
// 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)
|
||||
{
|
||||
[responder setBezeled:YES];
|
||||
[self _registerForEndEditingNote:responder];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_registerForEndEditingNote:(CPView)aTextField
|
||||
{
|
||||
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(_textFieldEditingDidEnd:) name:CPControlTextDidEndEditingNotification object:aTextField];
|
||||
}
|
||||
|
||||
- (void)_unregisterForEndEditingNote:(CPView)aTextField
|
||||
{
|
||||
[[CPNotificationCenter defaultCenter] removeObserver:self name:CPControlTextDidEndEditingNotification object:aTextField];
|
||||
}
|
||||
|
||||
- (void)_textFieldEditingDidEnd:(CPNotification)aNote
|
||||
{
|
||||
// FIXME: When you edit a text field and hit enter without any text modification, the CPControlTextDidEndEditingNotification
|
||||
// is NOT sent. This is a bug in CPTextField or CPControl according to cocoa.
|
||||
var textField = [aNote object];
|
||||
|
||||
[self _unregisterForEndEditingNote:textField];
|
||||
|
||||
if (!_isViewBased)
|
||||
{
|
||||
[self _setEditingState:NO forView:textField];
|
||||
[self _commitDataViewObjectValue:textField forColumn:_editingColumn andRow:_editingRow];
|
||||
}
|
||||
else
|
||||
[textField setBezeled:NO];
|
||||
|
||||
[self _resignFirstResponderWithoutSendingAction:textField];
|
||||
}
|
||||
|
||||
- (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
|
||||
@@ -0,0 +1,422 @@
|
||||
/*
|
||||
* CPTableView+Selection.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
|
||||
|
||||
|
||||
@implementation CPTableView (Selection)
|
||||
|
||||
|
||||
//Selecting Columns and Rows
|
||||
|
||||
/*!
|
||||
Sets the column selection using indexes.
|
||||
|
||||
@param columns a CPIndexSet of columns to select
|
||||
@param aFlag should extend the selection thereby retaining the previous selection
|
||||
*/
|
||||
- (void)selectColumnIndexes:(CPIndexSet)columns byExtendingSelection:(BOOL)shouldExtendSelection
|
||||
{
|
||||
// If we're out of range, just return
|
||||
if (([columns firstIndex] != CPNotFound && [columns firstIndex] < 0) || [columns lastIndex] >= [self numberOfColumns] || (!shouldExtendSelection && [columns isEqualToIndexSet:_selectedColumnIndexes]) || (shouldExtendSelection && [columns count] === 0))
|
||||
return;
|
||||
|
||||
// We deselect all rows when selecting columns.
|
||||
if ([_selectedRowIndexes count] > 0)
|
||||
{
|
||||
[self _updateHighlightWithOldRows:_selectedRowIndexes newRows:[CPIndexSet indexSet]];
|
||||
_selectedRowIndexes = [CPIndexSet indexSet];
|
||||
}
|
||||
|
||||
var previousSelectedIndexes = [_selectedColumnIndexes copy];
|
||||
|
||||
if (shouldExtendSelection)
|
||||
[_selectedColumnIndexes addIndexes:columns];
|
||||
else
|
||||
_selectedColumnIndexes = [columns copy];
|
||||
|
||||
[self _updateHighlightWithOldColumns:previousSelectedIndexes newColumns:_selectedColumnIndexes];
|
||||
[self _updateSelectedColumnBackgrounds];
|
||||
|
||||
if (_headerView)
|
||||
[_headerView setNeedsDisplay:YES];
|
||||
|
||||
[self _noteSelectionDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_setSelectedRowIndexes:(CPIndexSet)rows
|
||||
{
|
||||
if ([_selectedRowIndexes isEqualToIndexSet:rows])
|
||||
return;
|
||||
|
||||
var previousSelectedIndexes = _selectedRowIndexes;
|
||||
|
||||
_lastSelectedRow = ([rows count] > 0) ? [rows lastIndex] : -1;
|
||||
_selectedRowIndexes = [rows copy];
|
||||
|
||||
[self _updateHighlightWithOldRows:previousSelectedIndexes newRows:_selectedRowIndexes];
|
||||
|
||||
var binderClass = [[self class] _binderClassForBinding:@"selectionIndexes"];
|
||||
[[binderClass getBinding:@"selectionIndexes" forObject:self] reverseSetValueFor:@"selectedRowIndexes"];
|
||||
|
||||
[self _noteSelectionDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the row selection using indexes.
|
||||
|
||||
@param rows a CPIndexSet of rows to select
|
||||
@param aFlag should extend the selection thereby retaining the previous selection
|
||||
*/
|
||||
- (void)selectRowIndexes:(CPIndexSet)rows byExtendingSelection:(BOOL)shouldExtendSelection
|
||||
{
|
||||
if (([rows isEqualToIndexSet:_selectedRowIndexes] && [_selectedColumnIndexes count] === 0) ||
|
||||
(([rows firstIndex] != CPNotFound && [rows firstIndex] < 0) || [rows lastIndex] >= [self numberOfRows]) ||
|
||||
[self numberOfColumns] <= 0)
|
||||
return;
|
||||
|
||||
// We deselect all columns when selecting rows.
|
||||
if ([_selectedColumnIndexes count] > 0)
|
||||
{
|
||||
[self _updateHighlightWithOldColumns:_selectedColumnIndexes newColumns:[CPIndexSet indexSet]];
|
||||
_selectedColumnIndexes = [CPIndexSet indexSet];
|
||||
|
||||
[self _updateSelectedColumnBackgrounds];
|
||||
|
||||
if (_headerView)
|
||||
[_headerView setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
var newSelectedIndexes;
|
||||
if (shouldExtendSelection)
|
||||
{
|
||||
newSelectedIndexes = [_selectedRowIndexes copy];
|
||||
[newSelectedIndexes addIndexes:rows];
|
||||
}
|
||||
else
|
||||
newSelectedIndexes = [rows copy];
|
||||
|
||||
[self _setSelectedRowIndexes:newSelectedIndexes];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
cleanup a an indexset from the indexes that cannot be selected
|
||||
according to the table view delegate.
|
||||
*/
|
||||
- (CPIndexSet)_cleanUpSelectionRowIndexes:(CPIndexSet)anIndexSet
|
||||
{
|
||||
if ([self _delegateRespondsToSelectionIndexesForProposedSelection])
|
||||
{
|
||||
return [self _sendDelegateSelectionIndexesForProposedSelection:anIndexSet];
|
||||
}
|
||||
else if ([self _delegateRespondsToShouldSelectRow])
|
||||
{
|
||||
var indexesToRemove = [CPIndexSet new],
|
||||
currentIndex = [anIndexSet firstIndex];
|
||||
|
||||
while (currentIndex != CPNotFound)
|
||||
{
|
||||
if (![self _sendDelegateShouldSelectRow:currentIndex])
|
||||
[indexesToRemove addIndex:currentIndex];
|
||||
|
||||
currentIndex = [anIndexSet indexGreaterThanIndex:currentIndex];
|
||||
}
|
||||
|
||||
[anIndexSet removeIndexes:indexesToRemove];
|
||||
|
||||
return anIndexSet;
|
||||
}
|
||||
else
|
||||
return anIndexSet;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_updateHighlightWithOldRows:(CPIndexSet)oldRows newRows:(CPIndexSet)newRows
|
||||
{
|
||||
[self _enumerateViewsInRows:oldRows columns:_exposedColumns usingBlock:_BlockDeselectView];
|
||||
|
||||
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];
|
||||
}];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_updateHighlightWithOldColumns:(CPIndexSet)oldColumns newColumns:(CPIndexSet)newColumns
|
||||
{
|
||||
var blockDeselectHeader = function(column, stop)
|
||||
{
|
||||
var headerView = [_tableColumns[column] headerView];
|
||||
[headerView unsetThemeState:CPThemeStateSelected];
|
||||
};
|
||||
|
||||
var showSelection = _selectionHighlightStyle !== CPTableViewSelectionHighlightStyleNone;
|
||||
|
||||
[self _enumerateViewsInRows:_exposedRows columns:oldColumns usingBlock:_BlockDeselectView];
|
||||
[oldColumns enumerateIndexesUsingBlock:blockDeselectHeader];
|
||||
|
||||
if (_selectionHighlightStyle !== CPTableViewSelectionHighlightStyleNone)
|
||||
{
|
||||
[self _enumerateViewsInRows:_exposedRows columns:newColumns usingBlock:_BlockSelectView];
|
||||
[newColumns enumerateIndexesUsingBlock:function(column, stop)
|
||||
{
|
||||
var headerView = [_tableColumns[column] headerView];
|
||||
[headerView setThemeState:CPThemeStateSelected];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the index of the last selected column.
|
||||
*/
|
||||
- (int)selectedColumn
|
||||
{
|
||||
return [_selectedColumnIndexes lastIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns an index set of all the selected columns.
|
||||
*/
|
||||
- (CPIndexSet)selectedColumnIndexes
|
||||
{
|
||||
return _selectedColumnIndexes;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the index of the last selected row.
|
||||
*/
|
||||
- (int)selectedRow
|
||||
{
|
||||
return _lastSelectedRow;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns an index set with the indexes of all the selected rows.
|
||||
*/
|
||||
- (CPIndexSet)selectedRowIndexes
|
||||
{
|
||||
return [_selectedRowIndexes copy];
|
||||
}
|
||||
|
||||
/*!
|
||||
Deselects the column at a given index
|
||||
|
||||
@param anIndex the index of the column to deselect
|
||||
*/
|
||||
- (void)deselectColumn:(CPInteger)anIndex
|
||||
{
|
||||
var selectedColumnIndexes = [_selectedColumnIndexes copy];
|
||||
[selectedColumnIndexes removeIndex:anIndex];
|
||||
[self selectColumnIndexes:selectedColumnIndexes byExtendingSelection:NO];
|
||||
[self _noteSelectionDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Deselects a row at a given index
|
||||
|
||||
@param aRow the row to deselect
|
||||
*/
|
||||
- (void)deselectRow:(CPInteger)aRow
|
||||
{
|
||||
var selectedRowIndexes = [_selectedRowIndexes copy];
|
||||
[selectedRowIndexes removeIndex:aRow];
|
||||
[self selectRowIndexes:selectedRowIndexes byExtendingSelection:NO];
|
||||
[self _noteSelectionDidChange];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the number of selected columns
|
||||
*/
|
||||
- (CPInteger)numberOfSelectedColumns
|
||||
{
|
||||
return [_selectedColumnIndexes count];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the number of selected columns
|
||||
*/
|
||||
- (CPInteger)numberOfSelectedRows
|
||||
{
|
||||
return [_selectedRowIndexes count];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns YES if the column at a given index is selected, otherwise NO.
|
||||
|
||||
@param anIndex the index of a column
|
||||
@return YES if the column is selected, otherwise NO.
|
||||
*/
|
||||
- (BOOL)isColumnSelected:(CPInteger)anIndex
|
||||
{
|
||||
return [_selectedColumnIndexes containsIndex:anIndex];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns YES if the row at a given index is selected, otherwise NO.
|
||||
|
||||
@param aRow the index of a row
|
||||
@return YES if the row is selected, otherwise NO.
|
||||
*/
|
||||
- (BOOL)isRowSelected:(CPInteger)aRow
|
||||
{
|
||||
return [_selectedRowIndexes containsIndex:aRow];
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
Deselects all rows and columns
|
||||
*/
|
||||
- (void)deselectAll
|
||||
{
|
||||
[self selectRowIndexes:[CPIndexSet indexSet] byExtendingSelection:NO];
|
||||
[self selectColumnIndexes:[CPIndexSet indexSet] byExtendingSelection:NO];
|
||||
}
|
||||
|
||||
- (void)selectAll:(id)sender
|
||||
{
|
||||
if (_allowsMultipleSelection)
|
||||
{
|
||||
if (![self _sendDelegateSelectionShouldChangeInTableView])
|
||||
return;
|
||||
|
||||
if ([[self selectedColumnIndexes] count])
|
||||
[self selectColumnIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [self numberOfColumns])] byExtendingSelection:NO];
|
||||
else
|
||||
{
|
||||
var range = [self _cleanUpSelectionRowIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [self numberOfRows])]];
|
||||
[self selectRowIndexes:range byExtendingSelection:NO];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)deselectAll:(id)sender
|
||||
{
|
||||
if ([self allowsEmptySelection])
|
||||
{
|
||||
if (![self _sendDelegateSelectionShouldChangeInTableView])
|
||||
return;
|
||||
|
||||
[self deselectAll];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the number of columns in the table
|
||||
*/
|
||||
- (int)numberOfColumns
|
||||
{
|
||||
return [self _numberOfColumns];
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the number of rows in the receiver.
|
||||
*/
|
||||
- (int)numberOfRows
|
||||
{
|
||||
return _numberOfRows;
|
||||
}
|
||||
|
||||
- (int)_numberOfRows
|
||||
{
|
||||
var numberOfRows,
|
||||
contentBindingInfo = [self infoForBinding:@"content"];
|
||||
|
||||
if (contentBindingInfo)
|
||||
{
|
||||
var destination = [contentBindingInfo objectForKey:CPObservedObjectKey],
|
||||
keyPath = [contentBindingInfo objectForKey:CPObservedKeyPathKey];
|
||||
|
||||
numberOfRows = [[destination valueForKeyPath:keyPath] count];
|
||||
}
|
||||
else if (_dataSource && (_implementedDataSourceMethods & CPTableViewDataSource_numberOfRowsInTableView_))
|
||||
numberOfRows = [_dataSource numberOfRowsInTableView:self] || 0;
|
||||
else
|
||||
{
|
||||
if (_dataSource)
|
||||
CPLog(@"no content binding established and data source " + [_dataSource description] + " does not implement numberOfRowsInTableView:");
|
||||
numberOfRows = 0;
|
||||
}
|
||||
|
||||
return numberOfRows;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
Returns the cornerview for the scrollview
|
||||
*/
|
||||
- (CPView)cornerView
|
||||
{
|
||||
return _cornerView;
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the cornerview for the scrollview
|
||||
*/
|
||||
- (void)setCornerView:(CPView)aView
|
||||
{
|
||||
if (_cornerView === aView)
|
||||
return;
|
||||
|
||||
_cornerView = aView;
|
||||
|
||||
var scrollView = [self enclosingScrollView];
|
||||
|
||||
if ([scrollView isKindOfClass:[CPScrollView class]] && [scrollView documentView] === self)
|
||||
[scrollView _updateCornerAndHeaderView];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,343 @@
|
||||
/*
|
||||
* CPTableView+Tracking.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
|
||||
|
||||
|
||||
@implementation CPTableView (Tracking)
|
||||
|
||||
|
||||
/*
|
||||
@ignore
|
||||
*/
|
||||
- (BOOL)startTrackingAt:(CGPoint)aPoint
|
||||
{
|
||||
// Try to become the first responder, but if we can't, that's okay.
|
||||
[[self window] makeFirstResponder:self];
|
||||
|
||||
var row = [self rowAtPoint:aPoint];
|
||||
|
||||
_clickedRow = row;
|
||||
_clickedColumn = [self columnAtPoint:aPoint];
|
||||
|
||||
// If the user clicks outside a row then deselect everything.
|
||||
if (row < 0 && _allowsEmptySelection)
|
||||
{
|
||||
if ([self _sendDelegateSelectionShouldChangeInTableView])
|
||||
{
|
||||
var indexSet = [self _sendDelegateSelectionIndexesForProposedSelection:[CPIndexSet indexSet]];
|
||||
|
||||
[self _noteSelectionIsChanging];
|
||||
[self selectRowIndexes:indexSet byExtendingSelection:NO];
|
||||
}
|
||||
}
|
||||
|
||||
if ([self mouseDownFlags] & CPShiftKeyMask)
|
||||
_selectionAnchorRow = (ABS([_selectedRowIndexes firstIndex] - row) < ABS([_selectedRowIndexes lastIndex] - row)) ?
|
||||
[_selectedRowIndexes firstIndex] : [_selectedRowIndexes lastIndex];
|
||||
else
|
||||
_selectionAnchorRow = row;
|
||||
|
||||
//set ivars for startTrackingPoint and time...
|
||||
_startTrackingPoint = aPoint;
|
||||
_startTrackingTimestamp = new Date();
|
||||
|
||||
if ([self _dataSourceRespondsToSetObjectValueForTableColumnRow])
|
||||
_trackingPointMovedOutOfClickSlop = NO;
|
||||
|
||||
// if the table has drag support then we use mouseUp to select a single row.
|
||||
// otherwise it uses mouse down.
|
||||
if (row >= 0 && !([self _dataSourceRespondsToWriteRowsWithIndexesToPasteboard]))
|
||||
[self _updateSelectionWithMouseAtRow:row];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (CPMenu)menuForEvent:(CPEvent)theEvent
|
||||
{
|
||||
if (!([self _delegateRespondsToMenuForTableColumnRow]))
|
||||
return [super menuForEvent:theEvent];
|
||||
|
||||
var location = [self convertPoint:[theEvent locationInWindow] fromView:nil],
|
||||
row = [self rowAtPoint:location],
|
||||
column = [self columnAtPoint:location],
|
||||
tableColumn = [[self tableColumns] objectAtIndex:column];
|
||||
|
||||
return [self _sendDelegateMenuForTableColumn:tableColumn row:row];
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
*/
|
||||
- (void)trackMouse:(CPEvent)anEvent
|
||||
{
|
||||
// Prevent CPControl from eating the mouse events when we are in a drag session
|
||||
if (![_draggedRowIndexes count])
|
||||
{
|
||||
[self autoscroll:anEvent];
|
||||
[super trackMouse:anEvent];
|
||||
}
|
||||
else
|
||||
[CPApp sendEvent:anEvent];
|
||||
|
||||
if ([anEvent type] == CPLeftMouseUp)
|
||||
{
|
||||
_clickedRow = CPNotFound;
|
||||
_clickedColumn = CPNotFound;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
*/
|
||||
- (BOOL)continueTracking:(CGPoint)lastPoint at:(CGPoint)aPoint
|
||||
{
|
||||
var row = [self rowAtPoint:aPoint];
|
||||
|
||||
_clickedRow = row;
|
||||
_clickedColumn = [self columnAtPoint:aPoint];
|
||||
|
||||
// begin the drag is the datasource lets us, we've move at least +-3px vertical or horizontal,
|
||||
// or we're dragging from selected rows and we haven't begun a drag session
|
||||
if (!_isSelectingSession && [self _dataSourceRespondsToWriteRowsWithIndexesToPasteboard])
|
||||
{
|
||||
if (row >= 0 && (ABS(_startTrackingPoint.x - aPoint.x) > 3 || (_verticalMotionCanDrag && ABS(_startTrackingPoint.y - aPoint.y) > 3)) ||
|
||||
([_selectedRowIndexes containsIndex:row]))
|
||||
{
|
||||
if ([_selectedRowIndexes containsIndex:row])
|
||||
_draggedRowIndexes = [[CPIndexSet alloc] initWithIndexSet:_selectedRowIndexes];
|
||||
else
|
||||
_draggedRowIndexes = [CPIndexSet indexSetWithIndex:row];
|
||||
|
||||
//ask the datasource for the data
|
||||
var pboard = [CPPasteboard pasteboardWithName:CPDragPboard];
|
||||
|
||||
if ([self canDragRowsWithIndexes:_draggedRowIndexes atPoint:aPoint] && [self _sendDataSourceWriteRowsWithIndexes:_draggedRowIndexes toPasteboard:pboard])
|
||||
{
|
||||
var currentEvent = [CPApp currentEvent],
|
||||
offset = CGPointMakeZero(),
|
||||
tableColumns = [_tableColumns objectsAtIndexes:_exposedColumns];
|
||||
|
||||
// We deviate from the default Cocoa implementation here by asking for a view in stead of an image
|
||||
// We support both, but the view preferred over the image because we can mimic the rows we are dragging
|
||||
// by re-creating the data views for the dragged rows
|
||||
var view = [self dragViewForRowsWithIndexes:_draggedRowIndexes
|
||||
tableColumns:tableColumns
|
||||
event:currentEvent
|
||||
offset:offset];
|
||||
|
||||
if (!view)
|
||||
{
|
||||
var image = [self dragImageForRowsWithIndexes:_draggedRowIndexes
|
||||
tableColumns:tableColumns
|
||||
event:currentEvent
|
||||
offset:offset];
|
||||
view = [[CPImageView alloc] initWithFrame:CGRectMake(0, 0, [image size].width, [image size].height)];
|
||||
[view setImage:image];
|
||||
}
|
||||
|
||||
var bounds = [view bounds],
|
||||
firstRowFrame = [self frameOfDataViewAtColumn:0 row:[_draggedRowIndexes firstIndex]],
|
||||
viewLocation = CGPointMake(aPoint.x - CGRectGetWidth(bounds) / 2 + offset.x, aPoint.y - CGRectGetHeight(bounds) / 2 + offset.y + CGRectGetMinY(firstRowFrame));
|
||||
|
||||
[self dragView:view at:viewLocation offset:CGPointMakeZero() event:[CPApp currentEvent] pasteboard:pboard source:self slideBack:YES];
|
||||
_startTrackingPoint = nil;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
// The delegate disallowed the drag so clear the dragged row indexes
|
||||
_draggedRowIndexes = [CPIndexSet indexSet];
|
||||
}
|
||||
else if (ABS(_startTrackingPoint.x - aPoint.x) < 5 && ABS(_startTrackingPoint.y - aPoint.y) < 5)
|
||||
return YES;
|
||||
}
|
||||
|
||||
_isSelectingSession = YES;
|
||||
if (row >= 0 && row !== _lastTrackedRowIndex)
|
||||
{
|
||||
_lastTrackedRowIndex = row;
|
||||
[self _updateSelectionWithMouseAtRow:row];
|
||||
}
|
||||
|
||||
if ([self _dataSourceRespondsToSetObjectValueForTableColumnRow]
|
||||
&& !_trackingPointMovedOutOfClickSlop)
|
||||
{
|
||||
var CLICK_SPACE_DELTA = 5.0; // Stolen from AppKit/Platform/DOM/CPPlatformWindow+DOM.j
|
||||
if (ABS(aPoint.x - _startTrackingPoint.x) > CLICK_SPACE_DELTA
|
||||
|| ABS(aPoint.y - _startTrackingPoint.y) > CLICK_SPACE_DELTA)
|
||||
{
|
||||
_trackingPointMovedOutOfClickSlop = YES;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
|
||||
{
|
||||
_isSelectingSession = NO;
|
||||
|
||||
var CLICK_TIME_DELTA = 1000,
|
||||
columnIndex = -1,
|
||||
column,
|
||||
rowIndex,
|
||||
shouldEdit = YES;
|
||||
|
||||
_clickedRow = [self rowAtPoint:aPoint];
|
||||
_clickedColumn = [self columnAtPoint:aPoint];
|
||||
|
||||
if ([self _dataSourceRespondsToWriteRowsWithIndexesToPasteboard])
|
||||
{
|
||||
rowIndex = _clickedRow;
|
||||
|
||||
if (rowIndex !== -1)
|
||||
{
|
||||
if ([_draggedRowIndexes count] > 0)
|
||||
{
|
||||
_draggedRowIndexes = [CPIndexSet indexSet];
|
||||
return;
|
||||
}
|
||||
// if the table has drag support then we use mouseUp to select a single row.
|
||||
_previouslySelectedRowIndexes = [_selectedRowIndexes copy];
|
||||
[self _updateSelectionWithMouseAtRow:rowIndex];
|
||||
}
|
||||
}
|
||||
|
||||
// Accept either tableView:setObjectValue:forTableColumn:row: delegate method, or a binding.
|
||||
if (!_isViewBased && mouseIsUp
|
||||
&& !_trackingPointMovedOutOfClickSlop
|
||||
&& ([[CPApp currentEvent] clickCount] > 1)
|
||||
&& ([self _dataSourceRespondsToSetObjectValueForTableColumnRow]
|
||||
|| [self infoForBinding:@"content"]))
|
||||
{
|
||||
columnIndex = _clickedColumn;
|
||||
|
||||
if (columnIndex !== -1)
|
||||
{
|
||||
column = _tableColumns[columnIndex];
|
||||
|
||||
if ([column isEditable])
|
||||
{
|
||||
rowIndex = [self rowAtPoint:aPoint];
|
||||
|
||||
if (rowIndex !== -1)
|
||||
{
|
||||
if ([self _sendDelegateShouldEditTableColumn:column row:rowIndex])
|
||||
{
|
||||
[self editColumn:columnIndex row:rowIndex withEvent:[CPApp currentEvent] select:YES];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //end of editing conditional
|
||||
|
||||
//double click actions
|
||||
if ([[CPApp currentEvent] clickCount] === 2 && _doubleAction)
|
||||
{
|
||||
var target = _doubleClickTarget || _target,
|
||||
argument = [self infoForBinding:@"doubleClickArgument"] ? _doubleClickArgument : self;
|
||||
|
||||
[CPApp sendAction:_doubleAction to:target from:argument];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
*/
|
||||
- (CPDragOperation)draggingEntered:(id)sender
|
||||
{
|
||||
var location = [self convertPoint:[sender draggingLocation] fromView:nil],
|
||||
dropOperation = [self _proposedDropOperationAtPoint:location],
|
||||
row = [self _proposedRowAtPoint:location];
|
||||
|
||||
if (_retargetedDropRow != nil)
|
||||
row = _retargetedDropRow;
|
||||
|
||||
var draggedTypes = [self registeredDraggedTypes],
|
||||
count = [draggedTypes count],
|
||||
i = 0;
|
||||
|
||||
for (; i < count; i++)
|
||||
{
|
||||
if ([[[sender draggingPasteboard] types] containsObject:[draggedTypes objectAtIndex: i]])
|
||||
return [self _sendDataSourceValidateDrop:sender proposedRow:row proposedDropOperation:dropOperation];
|
||||
}
|
||||
|
||||
return CPDragOperationNone;
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
*/
|
||||
- (void)draggingExited:(id)sender
|
||||
{
|
||||
[_dropOperationFeedbackView removeFromSuperview];
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
*/
|
||||
- (void)draggingEnded:(id)sender
|
||||
{
|
||||
[self _draggingEnded];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_draggingEnded
|
||||
{
|
||||
_retargetedDropOperation = nil;
|
||||
_retargetedDropRow = nil;
|
||||
_draggedRowIndexes = [CPIndexSet indexSet];
|
||||
[_dropOperationFeedbackView removeFromSuperview];
|
||||
}
|
||||
|
||||
/*
|
||||
@ignore
|
||||
*/
|
||||
- (BOOL)wantsPeriodicDraggingUpdates
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,763 @@
|
||||
/*
|
||||
* CPTableView+Views.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
|
||||
@class CPTableContentBinder
|
||||
|
||||
|
||||
@implementation CPTableView (Views)
|
||||
|
||||
|
||||
/*!
|
||||
Loads all the data and dataviews for the receiver.
|
||||
*/
|
||||
- (void)load
|
||||
{
|
||||
if (_reloadAllRows)
|
||||
{
|
||||
[self _unloadDataViewsInRows:_exposedRows columns:_exposedColumns];
|
||||
|
||||
_exposedRows = [CPIndexSet indexSet];
|
||||
_exposedColumns = [CPIndexSet indexSet];
|
||||
|
||||
_reloadAllRows = NO;
|
||||
}
|
||||
|
||||
var exposedRect = [self exposedRect],
|
||||
exposedRows = [CPIndexSet indexSetWithIndexesInRange:[self _exposedRowsInRect:exposedRect]],
|
||||
exposedColumns = [self columnIndexesInRect:exposedRect],
|
||||
obscuredRows = [_exposedRows copy],
|
||||
obscuredColumns = [_exposedColumns copy];
|
||||
|
||||
[obscuredRows removeIndexes:exposedRows];
|
||||
[obscuredColumns removeIndexes:exposedColumns];
|
||||
|
||||
var newlyExposedRows = [exposedRows copy],
|
||||
newlyExposedColumns = [exposedColumns copy];
|
||||
|
||||
[newlyExposedRows removeIndexes:_exposedRows];
|
||||
[newlyExposedColumns removeIndexes:_exposedColumns];
|
||||
|
||||
var previouslyExposedRows = [exposedRows copy],
|
||||
previouslyExposedColumns = [exposedColumns copy];
|
||||
|
||||
[previouslyExposedRows removeIndexes:newlyExposedRows];
|
||||
[previouslyExposedColumns removeIndexes:newlyExposedColumns];
|
||||
|
||||
[self _unloadDataViewsInRows:previouslyExposedRows columns:obscuredColumns];
|
||||
[self _unloadDataViewsInRows:obscuredRows columns:previouslyExposedColumns];
|
||||
[self _unloadDataViewsInRows:obscuredRows columns:obscuredColumns];
|
||||
[self _unloadDataViewsInRows:newlyExposedRows columns:newlyExposedColumns];
|
||||
|
||||
[self _loadDataViewsInRows:previouslyExposedRows columns:newlyExposedColumns];
|
||||
[self _loadDataViewsInRows:newlyExposedRows columns:previouslyExposedColumns];
|
||||
[self _loadDataViewsInRows:newlyExposedRows columns:newlyExposedColumns];
|
||||
|
||||
_exposedRows = exposedRows;
|
||||
_exposedColumns = exposedColumns;
|
||||
|
||||
// Remove old draw view call
|
||||
// [_tableDrawView setFrame:exposedRect];
|
||||
|
||||
// [self setNeedsDisplay:YES]; // Not needed for structure changes
|
||||
|
||||
// if we have any columns to remove do that here
|
||||
|
||||
if (_needsDifferedTableColumnRemove)
|
||||
{
|
||||
var removeCount = [_differedColumnDataToRemove count],
|
||||
removeIndexes = [CPIndexSet indexSet];
|
||||
|
||||
for (var i = 0; i < removeCount; i++)
|
||||
{
|
||||
var data = _differedColumnDataToRemove[i],
|
||||
tableColumn = data.column,
|
||||
columnIdx = [_tableColumns indexOfObject:tableColumn];
|
||||
|
||||
if (columnIdx !== CPNotFound)
|
||||
[removeIndexes addIndex:columnIdx];
|
||||
}
|
||||
|
||||
if ([removeIndexes count] > 0)
|
||||
{
|
||||
var rowIndexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [self numberOfRows])];
|
||||
[self _unloadDataViewsInRows:rowIndexes columns:removeIndexes];
|
||||
|
||||
[_tableColumns removeObjectsAtIndexes:removeIndexes];
|
||||
|
||||
_dirtyTableColumnRangeIndex = 0;
|
||||
[self _recalculateTableColumnRanges];
|
||||
|
||||
// Shift cached index sets downwards to account for the removed columns
|
||||
var shiftIndexSet = function(indexSet)
|
||||
{
|
||||
var newSet = [CPIndexSet indexSet];
|
||||
[indexSet enumerateIndexesUsingBlock:function(idx, stop)
|
||||
{
|
||||
if (![removeIndexes containsIndex:idx])
|
||||
{
|
||||
var shift = 0,
|
||||
remIdx = [removeIndexes firstIndex];
|
||||
|
||||
while (remIdx !== CPNotFound && remIdx < idx)
|
||||
{
|
||||
shift++;
|
||||
remIdx = [removeIndexes indexGreaterThanIndex:remIdx];
|
||||
}
|
||||
|
||||
[newSet addIndex:idx - shift];
|
||||
}
|
||||
}];
|
||||
return newSet;
|
||||
};
|
||||
|
||||
_exposedColumns = shiftIndexSet(_exposedColumns);
|
||||
_selectedColumnIndexes = shiftIndexSet(_selectedColumnIndexes);
|
||||
|
||||
// Shift individual index variables
|
||||
var shiftIndex = function(idx)
|
||||
{
|
||||
if (idx === CPNotFound || idx === -1)
|
||||
return idx;
|
||||
|
||||
if ([removeIndexes containsIndex:idx])
|
||||
return CPNotFound;
|
||||
|
||||
var shift = 0,
|
||||
remIdx = [removeIndexes firstIndex];
|
||||
|
||||
while (remIdx !== CPNotFound && remIdx < idx)
|
||||
{
|
||||
shift++;
|
||||
remIdx = [removeIndexes indexGreaterThanIndex:remIdx];
|
||||
}
|
||||
|
||||
return idx - shift;
|
||||
};
|
||||
|
||||
_editingColumn = shiftIndex(_editingColumn);
|
||||
|
||||
_draggedColumnIndex = shiftIndex(_draggedColumnIndex);
|
||||
if (_draggedColumnIndex === CPNotFound)
|
||||
_draggedColumnIndex = -1;
|
||||
|
||||
_clickedColumn = shiftIndex(_clickedColumn);
|
||||
if (_clickedColumn === CPNotFound)
|
||||
_clickedColumn = -1;
|
||||
}
|
||||
|
||||
[_differedColumnDataToRemove removeAllObjects];
|
||||
_needsDifferedTableColumnRemove = NO;
|
||||
}
|
||||
|
||||
// Now clear all the leftovers
|
||||
// FIXME: this could be faster!
|
||||
for (var identifier in _cachedDataViews)
|
||||
{
|
||||
var dataViews = _cachedDataViews[identifier],
|
||||
count = dataViews.length;
|
||||
|
||||
while (count--)
|
||||
[dataViews[count] removeFromSuperview];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (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;
|
||||
|
||||
// If and edited view is about to be unloaded, cleanup its state before enqueuing.
|
||||
if ([columnIndexes containsIndex:_editingColumn] && [rowIndexes containsIndex:_editingRow])
|
||||
[self _resignEditedView];
|
||||
|
||||
var tableColumns = [_tableColumns objectsAtIndexes:columnIndexes];
|
||||
|
||||
[self _enumerateViewsInRows:rowIndexes tableColumns:tableColumns usingBlock:function(dataView, row, tableColumn, stop)
|
||||
{
|
||||
var dataViewsForRows = _dataViewsForRows[row],
|
||||
tableColumnUID = [tableColumn UID];
|
||||
|
||||
delete (dataViewsForRows[tableColumnUID]);
|
||||
|
||||
[self _sendDelegateWillRemoveView:dataView forTableColumn:tableColumn row:row];
|
||||
[self _enqueueReusableDataView:dataView];
|
||||
}];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (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];
|
||||
}
|
||||
}];
|
||||
|
||||
if (![rowIndexes count] || ![columnIndexes count])
|
||||
return;
|
||||
|
||||
[self _updateColumnRangesIfNecessary];
|
||||
|
||||
if (_numberOfHiddenColumns > 0)
|
||||
columnIndexes = [columnIndexes indexesPassingTest:function(idx, stop)
|
||||
{
|
||||
return ![_tableColumns[idx] isHidden];
|
||||
}];
|
||||
|
||||
[rowIndexes enumerateIndexesUsingBlock:function(rowIndex, stopRow)
|
||||
{
|
||||
|
||||
if (rowIndex >= [self numberOfRows])
|
||||
return;
|
||||
|
||||
if (!_dataViewsForRows[rowIndex])
|
||||
_dataViewsForRows[rowIndex] = {};
|
||||
|
||||
var dataViewsForRow = _dataViewsForRows[rowIndex],
|
||||
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.
|
||||
[columnIndexes enumerateIndexesUsingBlock:function(columnIndex, stopCol)
|
||||
{
|
||||
var tableColumn = _tableColumns[columnIndex],
|
||||
tableColumnUID = [tableColumn UID],
|
||||
dataView = [self _preparedViewAtColumn:columnIndex row:row isRowSelected:isRowSelected];
|
||||
|
||||
if ([dataView superview] !== self)
|
||||
[self addSubview:dataView];
|
||||
|
||||
if (focused && (isRowSelected || [self isColumnSelected:columnIndex]))
|
||||
[dataView setThemeState:CPThemeStateFirstResponder];
|
||||
|
||||
dataViewsForRow[tableColumnUID] = dataView;
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
- (CPView)_dequeueRowView
|
||||
{
|
||||
if (_cachedRowViews.length > 0)
|
||||
return _cachedRowViews.pop();
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)_updateAllVisibleRowViews
|
||||
{
|
||||
var focused = [self _isFocused];
|
||||
for (var idx in _visibleRowViews)
|
||||
{
|
||||
if (_visibleRowViews.hasOwnProperty(idx))
|
||||
[_visibleRowViews[idx] setSelected:[self isRowSelected:+idx] focused:focused];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_updateAllVisibleRowViewsFrames
|
||||
{
|
||||
var visibleWidth = MAX([self bounds].size.width, CGRectGetWidth([self exposedRect]));
|
||||
for (var idx in _visibleRowViews)
|
||||
{
|
||||
if (_visibleRowViews.hasOwnProperty(idx))
|
||||
{
|
||||
var rowView = _visibleRowViews[idx],
|
||||
rect = [rowView frame];
|
||||
rect.size.width = visibleWidth;
|
||||
[rowView setFrame:rect];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (CPView)preparedViewAtColumn:(CPInteger)column row:(CPInteger)row
|
||||
{
|
||||
return [self _preparedViewAtColumn:column row:row isRowSelected:[self isRowSelected:row]];
|
||||
}
|
||||
|
||||
- (CPView)_preparedViewAtColumn:(CPInteger)column row:(CPInteger)row isRowSelected:(BOOL)isRowSelected
|
||||
{
|
||||
var tableColumn = _tableColumns[column],
|
||||
tableColumnUID = [tableColumn UID],
|
||||
dataView = [self _newDataViewForRow:row tableColumn:tableColumn];
|
||||
|
||||
[dataView setFrame:[self frameOfDataViewAtColumn:column row:row]];
|
||||
|
||||
[self _setObjectValueForTableColumn:tableColumn row:row forView:dataView];
|
||||
|
||||
if (_selectionHighlightStyle !== CPTableViewSelectionHighlightStyleNone && (isRowSelected || [self isColumnSelected:column]))
|
||||
{
|
||||
_BlockSelectView(dataView, row, column);
|
||||
|
||||
if ([self _isFocused])
|
||||
[dataView setThemeState:CPThemeStateFirstResponder];
|
||||
else
|
||||
[dataView unsetThemeState:CPThemeStateFirstResponder];
|
||||
}
|
||||
else
|
||||
{
|
||||
_BlockDeselectView(dataView, row, column);
|
||||
// Ensure we clear this state if a view is reused
|
||||
[dataView unsetThemeState:CPThemeStateFirstResponder];
|
||||
}
|
||||
// FIX ME: for performance reasons we might consider diverging from cocoa and moving this to the reloadData method
|
||||
if (_implementedDelegateMethods & CPTableViewDelegate_tableView_isGroupRow_)
|
||||
{
|
||||
if ([_delegate tableView:self isGroupRow:row])
|
||||
{
|
||||
[_groupRows addIndex:row];
|
||||
[dataView setThemeState:CPThemeStateGroupRow];
|
||||
}
|
||||
else
|
||||
{
|
||||
[_groupRows removeIndexesInRange:CPMakeRange(row, 1)];
|
||||
[dataView unsetThemeState:CPThemeStateGroupRow];
|
||||
}
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
if (!_isViewBased)
|
||||
{
|
||||
// We use the 'row' and 'column' arguments here to check against the instance variables
|
||||
var isEditing = (row === _editingRow && column === _editingColumn);
|
||||
[self _setEditingState:isEditing forView:dataView];
|
||||
}
|
||||
|
||||
[self _sendDelegateWillDisplayView:dataView forTableColumn:tableColumn row:row];
|
||||
[self _applyToolTipToDataView:dataView forTableColumn:tableColumn row:row];
|
||||
|
||||
return dataView;
|
||||
}
|
||||
|
||||
- (void)_applyToolTipToDataView:(CPView)aDataView forTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRow
|
||||
{
|
||||
var tooltip = nil;
|
||||
|
||||
if (_implementedDelegateMethods & CPTableViewDelegate_tableView_toolTipForView_rect_tableColumn_row_mouseLocation_)
|
||||
tooltip = [self _sendDelegateToolTipForView:aDataView rect:[aDataView frame] tableColumn:aTableColumn row:aRow mouseLocation:CGPointMakeZero()];
|
||||
|
||||
[aDataView setToolTip:tooltip];
|
||||
}
|
||||
|
||||
- (void)_setObjectValueForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRow forView:(CPView)aDataView
|
||||
{
|
||||
[self _setObjectValueForTableColumn:aTableColumn row:aRow forView:aDataView useCache:!_invalidateObjectValuesCache];
|
||||
}
|
||||
|
||||
- (void)_setObjectValueForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRow forView:(CPView)aDataView useCache:(BOOL)useCache
|
||||
{
|
||||
var providedByDataSource = NO;
|
||||
|
||||
if (_implementedDataSourceMethods & CPTableViewDataSource_tableView_objectValueForTableColumn_row_)
|
||||
{
|
||||
var objectValue = [self _objectValueForTableColumn:aTableColumn row:aRow useCache:useCache];
|
||||
[aDataView setObjectValue:objectValue];
|
||||
providedByDataSource = YES;
|
||||
}
|
||||
|
||||
// This gives the table column an opportunity to apply its bindings.
|
||||
// It will override the value set above if there is an explicit column binding.
|
||||
var columnHasBindings = [[[CPBinder allBindingsForObject:aTableColumn] allKeys] count] > 0;
|
||||
|
||||
if (columnHasBindings)
|
||||
{
|
||||
[aTableColumn _prepareDataView:aDataView forRow:aRow];
|
||||
}
|
||||
// Only forcefully bind the raw content object if the data source didn't already provide a formatted value
|
||||
else if (_contentBindingExplicitlySet && !providedByDataSource)
|
||||
{
|
||||
[self _prepareContentBindedDataView:aDataView forRow:aRow];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_prepareContentBindedDataView:(CPView)dataView forRow:(CPInteger)aRow
|
||||
{
|
||||
var binder = [CPTableContentBinder getBinding:@"content" forObject:self],
|
||||
content = [binder content],
|
||||
rowContent = [content objectAtIndex:aRow];
|
||||
|
||||
[dataView setObjectValue:rowContent];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_layoutViewsForRowIndexes:(CPIndexSet)rowIndexes columnIndexes:(CPIndexSet)columnIndexes
|
||||
{
|
||||
[self _enumerateViewsInRows:rowIndexes columns:columnIndexes usingBlock:function(view, row, column, stop)
|
||||
{
|
||||
[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];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (CPView)_newDataViewForRow:(CPInteger)aRow tableColumn:(CPTableColumn)aTableColumn
|
||||
{
|
||||
var view = nil;
|
||||
|
||||
if (_viewForTableColumnRowSelector)
|
||||
view = self.isa.objj_msgSend2(self, _viewForTableColumnRowSelector, aTableColumn, aRow);
|
||||
|
||||
if (!view)
|
||||
{
|
||||
// For cell-based tables, use the dataView prototype identifier as view identifier
|
||||
// instead of column identifier because 1/ the column identifier may be nil
|
||||
// and 2/ the tableColumn dataView may change after the column identifier was set.
|
||||
var identifier;
|
||||
|
||||
if (_isViewBased)
|
||||
{
|
||||
identifier = [aTableColumn identifier];
|
||||
view = [self makeViewWithIdentifier:identifier owner:_delegate];
|
||||
}
|
||||
else
|
||||
{
|
||||
identifier = [[aTableColumn dataView] UID];
|
||||
view = [self makeViewWithIdentifier:identifier owner:_delegate];
|
||||
|
||||
if (!view)
|
||||
view = [aTableColumn _newDataView];
|
||||
}
|
||||
|
||||
[view setIdentifier:identifier];
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
/*
|
||||
Returns a view with the specified identifier.
|
||||
|
||||
@param identifier The view identifier. Must not be nil.
|
||||
@param owner The owner of the CIB that may be loaded and instantiated to create a new view with the particular identifier.
|
||||
@return A view for the row.
|
||||
|
||||
@discussion
|
||||
Typically identifier is associated with an external CIB and the table view will automatically instantiate the CIB with the provided owner. The owner of the CIB that may be loaded and instantiated to create a new view with the particular identifier is typically the table view’s delegate. The owner is useful in setting up outlets and target and actions from the view.
|
||||
|
||||
This method will typically be called by the delegate in tableView:viewForTableColumn:row:, but it can also be overridden to provide custom views for the identifier. This method may also return a reused view with the same identifier that was no longer available on screen.
|
||||
*/
|
||||
- (id)makeViewWithIdentifier:(CPString)anIdentifier owner:(id)anOwner
|
||||
{
|
||||
if (!anIdentifier)
|
||||
return nil;
|
||||
|
||||
var view = nil,
|
||||
// See if we have some reusable views available
|
||||
reusableViews = _cachedDataViews[anIdentifier];
|
||||
|
||||
if (reusableViews && reusableViews.length)
|
||||
view = reusableViews.pop();
|
||||
// Otherwise see if we have a view in the cib with this identifier
|
||||
else if (_isViewBased)
|
||||
view = [self _unarchiveViewWithIdentifier:anIdentifier owner:anOwner];
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns an instance of CPView
|
||||
|
||||
@param column The index of the column in the tableColumn array
|
||||
@param row The index of the row
|
||||
@param makeIfNecessary YES if a view is required, NO if you want to update properties on a view, if one is available.
|
||||
|
||||
@discussion
|
||||
This method first attempts to return an available view, which is generally in the visible area. If there is no available view, and makeIfNecessary is YES, a prepared temporary view is returned. If makeIfNecessary is NO, and the view is not available, nil will be returned.
|
||||
|
||||
An exception will be thrown if row is an invalid row index and if column is an invalid column index
|
||||
*/
|
||||
- (id)viewAtColumn:(CPInteger)column row:(CPInteger)row makeIfNecessary:(BOOL)makeIfNecessary
|
||||
{
|
||||
if (row > (_numberOfRows - 1))
|
||||
[CPException raise:CPInvalidArgumentException
|
||||
reason:@"Row " + row + " out of row range [0-" + (_numberOfRows - 1) + "] for rowViewAtRow:createIfNeeded:"];
|
||||
|
||||
if (column > ([self _numberOfColumns] - 1))
|
||||
[CPException raise:CPInvalidArgumentException
|
||||
reason:@"Column " + column + " out of row range [0-" + ([self _numberOfColumns]- 1) + "] for rowViewAtRow:createIfNeeded:"];
|
||||
|
||||
var dataViewsForRow = _dataViewsForRows[row],
|
||||
tableColumn = _tableColumns[column],
|
||||
tableColumnUID = [tableColumn UID],
|
||||
view = dataViewsForRow ? dataViewsForRow[tableColumnUID] : nil;
|
||||
|
||||
if (!makeIfNecessary)
|
||||
return view || nil;
|
||||
|
||||
if (!view)
|
||||
{
|
||||
if (!dataViewsForRow)
|
||||
{
|
||||
dataViewsForRow = {};
|
||||
_dataViewsForRows[row] = dataViewsForRow;
|
||||
}
|
||||
|
||||
// Here we will add this view to the tableView and add it to the exposedRows adn columns.
|
||||
// The view will be deleted if necessary during the next run loop cycle of the table view
|
||||
// This is how cocoa works
|
||||
view = [self preparedViewAtColumn:column row:row];
|
||||
|
||||
if ([view superview] !== self)
|
||||
[self addSubview:view];
|
||||
|
||||
dataViewsForRow[tableColumnUID] = view;
|
||||
|
||||
[_exposedRows addIndex:row];
|
||||
[_exposedColumns addIndex:column];
|
||||
|
||||
// Make sure to layout the tableView again
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (CPView)_unarchiveViewWithIdentifier:(CPString)anIdentifier owner:(id)anOwner
|
||||
{
|
||||
var cib = [_archivedDataViews objectForKey:anIdentifier];
|
||||
|
||||
if (!cib && !_unavailable_custom_cibs[anIdentifier])
|
||||
{
|
||||
var bundle = anOwner ? [CPBundle bundleForClass:[anOwner class]] : [CPBundle mainBundle];
|
||||
cib = [[CPCib alloc] initWithCibNamed:anIdentifier bundle:bundle];
|
||||
}
|
||||
|
||||
if (!cib)
|
||||
{
|
||||
_unavailable_custom_cibs[anIdentifier] = YES;
|
||||
return nil;
|
||||
}
|
||||
|
||||
var objects = [],
|
||||
load = [cib instantiateCibWithOwner:anOwner topLevelObjects:objects];
|
||||
|
||||
if (!load)
|
||||
return nil;
|
||||
|
||||
var count = objects.length;
|
||||
|
||||
while (count--)
|
||||
{
|
||||
var obj = objects[count];
|
||||
|
||||
if ([obj isKindOfClass:[CPView class]])
|
||||
{
|
||||
[obj setIdentifier:anIdentifier];
|
||||
[obj setAutoresizingMask:CPViewNotSizable];
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)_updateIsViewBased
|
||||
{
|
||||
if ([self _delegateRespondsToViewForTableColumn])
|
||||
_viewForTableColumnRowSelector = @selector(_sendDelegateViewForTableColumn:row:);
|
||||
else if ([self _delegateRespondsToDataViewForTableColumn])
|
||||
_viewForTableColumnRowSelector = @selector(_sendDelegateDataViewForTableColumn:row:);
|
||||
|
||||
_isViewBased = (_viewForTableColumnRowSelector != nil || _archivedDataViews != nil);
|
||||
}
|
||||
|
||||
/*!
|
||||
Allows the enumeration of all the table views that are known to the table view.
|
||||
|
||||
@param handler The function to apply to elements in the set.
|
||||
|
||||
The function takes three arguments:
|
||||
|
||||
@param dataView
|
||||
The view for the column and row.
|
||||
@param column
|
||||
The column index of the view.
|
||||
@param row
|
||||
The row index of the view.
|
||||
*/
|
||||
|
||||
- (void)enumerateAvailableViewsUsingBlock:(Function/*CPView *dataView, CPInteger row, CPInteger column*, @ref stop*/)handler
|
||||
{
|
||||
[self reloadData];
|
||||
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
|
||||
[self _enumerateViewsInRows:_exposedRows columns:_exposedColumns usingBlock:handler];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
|
||||
- (void)_enumerateViewsInRows:(CPIndexSet)rowIndexes columns:(CPIndexSet)columnIndexes usingBlock:(Function/*CPView dataView, CPInteger row, CPInteger column, @ref stop*/)handler
|
||||
{
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
|
||||
[rowIndexes enumerateIndexesUsingBlock:function(rowIndex, stopRow)
|
||||
{
|
||||
var dataViewsForRow = _dataViewsForRows[rowIndex];
|
||||
|
||||
if (!dataViewsForRow)
|
||||
return;
|
||||
|
||||
var row = rowIndex;
|
||||
|
||||
[columnIndexes enumerateIndexesUsingBlock:function(columnIndex, stopCol)
|
||||
{
|
||||
var tableColumnUID = [_tableColumns[columnIndex] UID],
|
||||
view = dataViewsForRow[tableColumnUID];
|
||||
|
||||
if (view)
|
||||
handler(view, row, columnIndex, stopCol);
|
||||
|
||||
if (stopCol())
|
||||
stopRow(YES);
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)_enumerateViewsInRows:(CPIndexSet)rowIndexes tableColumns:(CPArray)tableColumns usingBlock:(Function/*CPView dataView, CPInteger row, CPtableColumn tableColumn, CPInteger column, @ref stop*/)handler
|
||||
{
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
|
||||
[rowIndexes enumerateIndexesUsingBlock:function(rowIndex, stopRow)
|
||||
{
|
||||
var dataViewsForRow = _dataViewsForRows[rowIndex];
|
||||
|
||||
if (!dataViewsForRow)
|
||||
return;
|
||||
|
||||
var row = rowIndex;
|
||||
|
||||
[tableColumns enumerateObjectsUsingBlock:function(tableColumn, idx, stopCol)
|
||||
{
|
||||
var tableColumnUID = [tableColumn UID],
|
||||
view = dataViewsForRow[tableColumnUID];
|
||||
|
||||
if (view)
|
||||
handler(view, row, tableColumn, stopCol);
|
||||
|
||||
if (stopCol())
|
||||
stopRow(YES);
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)_enqueueReusableDataView:(CPView)aDataView
|
||||
{
|
||||
if (!aDataView)
|
||||
return;
|
||||
|
||||
// FIXME: yuck!
|
||||
var identifier = [aDataView identifier];
|
||||
|
||||
if ([aDataView hasThemeState:CPThemeStateSelectedDataView])
|
||||
[aDataView unsetThemeState:CPThemeStateSelectedDataView];
|
||||
|
||||
if (!_cachedDataViews[identifier])
|
||||
_cachedDataViews[identifier] = [aDataView];
|
||||
else
|
||||
_cachedDataViews[identifier].push(aDataView);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* CPTableView.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
|
||||
*/
|
||||
|
||||
/*
|
||||
CPTableView is divided by responsibility. CPTableViewCore.j holds the class, its instance
|
||||
variables, initialization and display attributes; each other file holds a category or a
|
||||
helper class, and imports CPTableViewCore.j. This file imports them all, so an import of
|
||||
CPTableView.j brings the complete class.
|
||||
*/
|
||||
|
||||
@import "CPTableViewCore.j"
|
||||
@import "_CPTableRowView.j"
|
||||
@import "CPTableView+Columns.j"
|
||||
@import "CPTableView+Selection.j"
|
||||
@import "CPTableView+Layout.j"
|
||||
@import "CPTableView+Views.j"
|
||||
@import "CPTableView+Drawing.j"
|
||||
@import "CPTableView+Tracking.j"
|
||||
@import "CPTableView+Dragging.j"
|
||||
@import "CPTableView+Responder.j"
|
||||
@import "CPTableView+Editing.j"
|
||||
@import "CPTableView+DataSource.j"
|
||||
@import "CPTableView+Delegate.j"
|
||||
@import "CPTableView+Bindings.j"
|
||||
@import "CPTableView+Coding.j"
|
||||
@import "CPTableCellView.j"
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* _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
|
||||
Reference in new issue
Block a user