Merge branch 'jake' into enstore_jake

Conflicts:
	AppKit/CPTableView.j
This commit is contained in:
Klaas Pieter Annema committed 2010-02-01 11:07:42 +01:00
commit 82be6c243c
29 files changed
+451 -148

No files matched your search

+179 -37
View File
@@ -122,6 +122,13 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
@end
/*!
@ingroup appkit
@class CPTableView
CPTableView object displays record-oriented data in a table and allows the user to edit values and resize and rearrange columns.
A CPTableView requires you to set a dataSource which implements numberOfRowsInTableView: and tableView:objectValueForTableColumn:row:
*/
@implementation CPTableView : CPControl
{
id _dataSource;
@@ -146,6 +153,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
//Configuring Behavior
BOOL _allowsColumnReordering;
BOOL _allowsColumnResizing;
BOOL _allowsColumnSelection;
BOOL _allowsMultipleSelection;
BOOL _allowsEmptySelection;
@@ -266,6 +274,11 @@ window.setTimeout(function(){
return self;
}
/*!
Sets the receiverÕs data source to a given object.
@param anObject The data source for the receiver. The object must implement the appropriate methods.
*/
- (void)setDataSource:(id)aDataSource
{
if (_dataSource === aDataSource)
@@ -303,6 +316,9 @@ window.setTimeout(function(){
[self reloadData];
}
/*!
Returns the object that provides the data displayed by the receiver.
*/
- (id)dataSource
{
return _dataSource;
@@ -310,6 +326,11 @@ window.setTimeout(function(){
//Loading Data
/*!
Reloads the data for only the specified rows and columns.
@param rowIndexes The indexes of the rows to update.
@param columnIndexes The indexes of the columns to update.
*/
- (void)reloadDataForRowIndexes:(CPIndexSet)rowIndexes columnIndexes:(CPIndexSet)columnIndexes
{
[self reloadData];
@@ -317,7 +338,10 @@ window.setTimeout(function(){
// [_previouslyExposedColumns removeIndexes:columnIndexes];
}
/*!
Reloads the data for all rows and columns.
*/
- (void)reloadData
{
if (!_dataSource)
@@ -334,7 +358,10 @@ window.setTimeout(function(){
}
//Target-action Behavior
/*!
Sets the message sent to the target when the user double-clicks an uneditable cell or a column header to a given selector.
@param aSelector The message the receiver sends to its target when the user double-clicks an uneditable cell or a column header.
*/
- (void)setDoubleAction:(SEL)anAction
{
_doubleAction = anAction;
@@ -371,6 +398,10 @@ window.setTimeout(function(){
return _allowsColumnResizing;
}
/*!
Controls whether the user can select more than one row or column at a time.
@param aFlag YES to allow the user to select multiple rows or columns, otherwise NO.
*/
- (void)setAllowsMultipleSelection:(BOOL)shouldAllowMultipleSelection
{
_allowsMultipleSelection = !!shouldAllowMultipleSelection;
@@ -381,6 +412,10 @@ window.setTimeout(function(){
return _allowsMultipleSelection;
}
/*!
Controls whether the receiver allows zero rows or columns to be selected.
@param aFlag YES if an empty selection is allowed, otherwise NO.
*/
- (void)setAllowsEmptySelection:(BOOL)shouldAllowEmptySelection
{
_allowsEmptySelection = !!shouldAllowEmptySelection;
@@ -391,6 +426,11 @@ window.setTimeout(function(){
return _allowsEmptySelection;
}
/*!
Controls whether the user can select an entire column by clicking its header.
@param aFlag YES to allow the user to select columns, otherwise NO.
*/
- (void)setAllowsColumnSelection:(BOOL)shouldAllowColumnSelection
{
_allowsColumnSelection = !!shouldAllowColumnSelection;
@@ -439,13 +479,12 @@ window.setTimeout(function(){
return _rowHeight;
}
/*!
Sets whether the receiver uses the standard alternating row colors for its background.
@param aFlag YES to specify standard alternating row colors for the background, NO to specify a solid color.
*/
- (void)setUsesAlternatingRowBackgroundColors:(BOOL)shouldUseAlternatingRowBackgroundColors
{
// TODO:need to look at how one actually sets the alternating row, a tip at:
// http://forums.macnn.com/79/developer-center/228347/nstableview-alternating-row-colors/
// otherwise this may not be feasible or may introduce an additional change req'd in CP
// we'd probably need to iterate through rowId % 2 == 0 and setBackgroundColor with
// whatever the alternating row color is.
_usesAlternatingRowBackgroundColors = shouldUseAlternatingRowBackgroundColors;
}
@@ -454,6 +493,11 @@ window.setTimeout(function(){
return _usesAlternatingRowBackgroundColors;
}
/*!
Sets the colors for the rows as they alternate. The number of colors can be arbitrary. By deafult these colors are white and light blue.
@param anArray an array of CPColors
*/
- (void)setAlternatingRowBackgroundColors:(CPArray)alternatingRowBackgroundColors
{
if ([_alternatingRowBackgroundColors isEqual:alternatingRowBackgroundColors])
@@ -490,6 +534,11 @@ window.setTimeout(function(){
}
}
/*!
Sets the highlight color for rows. By default this color is blue.
@param aColor a CPColor
*/
- (void)setSelectionHightlightColor:(CPColor)aColor
{
_selectionHightlightColor = aColor;
@@ -505,6 +554,10 @@ window.setTimeout(function(){
* - setIndicatorImage:inTableColumn:
*/
/*!
Sets the grid color in the non highlighted state.
@param aColor a CPColor
*/
- (void)setGridColor:(CPColor)aColor
{
if (_gridColor === aColor)
@@ -520,6 +573,11 @@ window.setTimeout(function(){
return _gridColor;
}
/*!
Sets the grid style mask to specify if no grid lines, vertical grid lines, or horizontal grid lines should be displayed.
@param gridType The grid style mask. CPTableViewGridNone, CPTableViewSolidVerticalGridLineMask, CPTableViewSolidHorizontalGridLineMask
*/
- (void)setGridStyleMask:(unsigned)aGrideStyleMask
{
if (_gridStyleMask === aGrideStyleMask)
@@ -537,6 +595,10 @@ window.setTimeout(function(){
//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];
@@ -550,6 +612,10 @@ window.setTimeout(function(){
[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)
@@ -576,6 +642,12 @@ window.setTimeout(function(){
[self setNeedsLayout];
}
/*!
Moves the column and heading at a given index to a new given index.
@param columnIndex The current index of the column to move.
@param newIndex The new index for the moved column.
*/
- (void)moveColumn:(unsigned)fromIndex toColumn:(unsigned)toIndex
{
fromIndex = +fromIndex;
@@ -628,6 +700,12 @@ window.setTimeout(function(){
}
//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
@@ -656,6 +734,11 @@ window.setTimeout(function(){
[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] || (([rows firstIndex] != CPNotFound && [rows firstIndex] < 0) || [rows lastIndex] >= [self numberOfRows]))
@@ -768,13 +851,17 @@ window.setTimeout(function(){
- (void)deselectColumn:(CPInteger)aColumn
{
[_selectedColumnIndexes removeIndex:aColumn];
var selectedColumnIndexes = [_selectedColumnIndexes copy];
[selectedColumnIndexes removeIndex:aColumn];
[self selectColumnIndexes:selectedColumnIndexes byExtendingSelection:NO];
[self _noteSelectionDidChange];
}
- (void)deselectRow:(CPInteger)aRow
{
[_selectedRowIndexes removeIndex:aRow];
var selectedRowIndexes = [_selectedRowIndexes copy];
[selectedRowIndexes removeIndex:aRow];
[self selectColumnIndexes:selectedRowIndexes byExtendingSelection:NO];
[self _noteSelectionDidChange];
}
@@ -808,6 +895,10 @@ window.setTimeout(function(){
* - allowsTypeSelect
* - setAllowsTypeSelect:
*/
/*!
Deselects all rows
*/
- (void)deselectAll
{
[self selectRowIndexes:[CPIndexSet indexSet] byExtendingSelection:NO];
@@ -955,6 +1046,11 @@ window.setTimeout(function(){
// Complexity:
// O(1)
/*!
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
{
// If we have no rows, then we won't intersect anything.
@@ -985,6 +1081,11 @@ window.setTimeout(function(){
// Complexity:
// O(lg Columns) if table view contains no hidden columns
// O(Columns) if table view contains hidden columns
/*!
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
{
var column = MAX(0, [self columnAtPoint:_CGPointMake(aRect.origin.x, 0.0)]),
@@ -1180,6 +1281,10 @@ window.setTimeout(function(){
}
/*!
Sets the column autoresizing style of the receiver to a given style.
@param aStyle The column autoresizing style for the receiver. CPTableViewNoColumnAutoresizing, CPTableViewUniformColumnAutoresizingStyle, CPTableViewLastColumnOnlyAutoresizingStyle, CPTableViewFirstColumnOnlyAutoresizingStyle
*/
- (void)setColumnAutoresizingStyle:(unsigned)style
{
//FIX ME: CPTableViewSequentialColumnAutoresizingStyle and CPTableViewReverseSequentialColumnAutoresizingStyle are not yet implemented
@@ -1191,6 +1296,9 @@ window.setTimeout(function(){
return _columnAutoResizingStyle;
}
/*!
Resizes the last column if thereÕs room so the receiver fits exactly within its enclosing clip view.
*/
- (void)sizeLastColumnToFit
{
var superview = [self superview];
@@ -1265,11 +1373,19 @@ window.setTimeout(function(){
* - scrollColumnToVisible:
*/
/*!
Scrolls the receiver vertically in an enclosing NSClipView so the row specified by rowIndex is visible.
@param aRowIndex the index of the row to scroll to.
*/
- (void)scrollRowToVisible:(int)rowIndex
{
[self scrollRectToVisible:[self rectOfRow:rowIndex]];
}
/*!
Scrolls the receiver and header view horizontally in an enclosing NSClipView so the column specified by columnIndex is visible.
@param aColumnIndex the index of the column to scroll to.
*/
- (void)scrollColumnToVisible:(int)columnIndex
{
[self scrollRectToVisible:[self rectOfColumn:columnIndex]];
@@ -1429,6 +1545,11 @@ window.setTimeout(function(){
* - setVerticalMotionCanBeginDrag:
* - verticalMotionCanBeginDrag
*/
/*!
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 YES;
@@ -1500,8 +1621,8 @@ window.setTimeout(function(){
_dragOperationDefaultMask = mask;
}
/*
this should be called inside tableView:validateDrop:... method
/*!
This should be called inside tableView:validateDrop:... method
either drop on or above,
specify the row as -1 to select the whole table for drop on
*/
@@ -1517,16 +1638,16 @@ window.setTimeout(function(){
_retargetedDropOperation = operation;
}
/*
can be:
/*!
sets the feedback style for when the table is the destination of a drag operation
Can be:
None
Regular
Source List
FIX ME: this should vary up the highlight color, currently nothing is being done with it
*/
- (void)setDraggingDestinationFeedbackStyle:(CPTableViewDraggingDestinationFeedbackStyle)aStyle
{
//FIX ME: this should vary up the highlight color, currently nothing is being done with it
_destinationDragStyle = aStyle;
}
@@ -1535,6 +1656,10 @@ window.setTimeout(function(){
return _destinationDragStyle;
}
/*!
Sets whether vertical motion is treated as a drag or selection change to flag.
@param aFlag If flag is NO then vertical motion will not start a drag. The default is YES.
*/
- (void)setVerticalMotionCanBeginDrag:(BOOL)aFlag
{
_verticalMotionCanDrag = aFlag;
@@ -1818,7 +1943,10 @@ window.setTimeout(function(){
}
- (void)_drawRect:(CGRect)aRect
{
{
// FIX ME: All three of these methods will likely need to be rewritten for 1.0
// We've got grid drawing in highlightSelection and crap everywhere.
var exposedRect = [self _exposedRect];
[self drawBackgroundInClipRect:exposedRect];
@@ -1854,7 +1982,7 @@ window.setTimeout(function(){
// CGContextFillRect(context, CGRectIntersection(aRect, fillRect));
// console.profile("row-paint");
var exposedRows = [self rowsInRect:aRect],
firstRow = exposedRows.location,
firstRow = exposedRows.location -1,
lastRow = CPMaxRange(exposedRows) - 1,
colorIndex = MIN(exposedRows.length, colorCount),
heightFilled = 0.0;
@@ -2022,33 +2150,34 @@ window.setTimeout(function(){
CGContextBeginPath(context);
gridStyleMask = [self gridStyleMask];
for(var i=0; i < count2-1; i++)
for(var i=0; i < count2; i++)
{
var rect = [self rectOfRow:indexes[i]],
minX = _CGRectGetMinX(rect) - 0.5,
maxX = _CGRectGetMaxX(rect) - 0.5,
minY = _CGRectGetMinY(rect) - 0.5,
maxY = _CGRectGetMaxY(rect) - 0.5;
var rect = objj_msgSend(self, rectSelector, indexes[i]),
minX = CGRectGetMinX(rect) - 0.5,
maxX = CGRectGetMaxX(rect) - 0.5,
minY = CGRectGetMinY(rect) - 0.5,
maxY = CGRectGetMaxY(rect) - 0.5;
//FIX ME: if there are vertical lines we need to make them white too...
/*if (gridStyleMask & CPTableViewSolidVerticalGridLineMask)
if ([_selectedRowIndexes count] >= 1 && gridStyleMask & CPTableViewSolidVerticalGridLineMask)
{
var exposedColumns = [self columnIndexesInRect:aRect],
columnIndexes = [],
exposedColumns2 = CPMakeRange([exposedColumns firstIndex], [exposedColumns lastIndex] - firstColumn + 1);
[exposedColumns getIndexes:columnIndexes maxCount:-1 inIndexRange:exposedColumns2],
columnCount = [exposedColumns count];
for(var c = 0; c < columnCount - 1; c++)
exposedColumnIndexes = [],
firstExposedColumn = [exposedColumns firstIndex],
exposedRange = CPMakeRange(firstExposedColumn, [exposedColumns lastIndex] - firstExposedColumn + 1);
[exposedColumns getIndexes:exposedColumnIndexes maxCount:-1 inIndexRange:exposedRange];
var exposedColumnCount = [exposedColumnIndexes count];
for(var c = firstExposedColumn; c < exposedColumnCount; c++)
{
var colRect = [self rectOfColumn:columnIndexes[c]],
colX = _CGRectGetMaxX(rect) - 0.5;
console.log("colX");
//console.log(columnIndexes);
var colRect = [self rectOfColumn:exposedColumnIndexes[c]],
colX = CGRectGetMaxX(colRect) + 0.5;
//console.log(colX);
CGContextMoveToPoint(context, colX, minY);
CGContextAddLineToPoint(context, colX, maxY);
}
}*/
}
CGContextMoveToPoint(context, minX, maxY);
CGContextAddLineToPoint(context, maxX, maxY);
@@ -2121,12 +2250,17 @@ window.setTimeout(function(){
*/
/*
@ignore
*/
- (BOOL)tracksMouseOutsideOfFrame
{
return YES;
}
/* ignore */
/*
@ignore
*/
- (BOOL)startTrackingAt:(CGPoint)aPoint
{
var row = [self rowAtPoint:aPoint];
@@ -2160,6 +2294,9 @@ window.setTimeout(function(){
return YES;
}
/*
@ignore
*/
- (void)trackMouse:(CPEvent)anEvent
{
// Prevent CPControl from eating the mouse events when we are in a drag session
@@ -2169,7 +2306,9 @@ window.setTimeout(function(){
[CPApp sendEvent:anEvent];
}
/* ignore */
/*
@ignore
*/
- (BOOL)continueTracking:(CGPoint)lastPoint at:(CGPoint)aPoint
{
var row = [self rowAtPoint:aPoint];
@@ -2244,6 +2383,9 @@ window.setTimeout(function(){
return YES;
}
/*!
@ignore
*/
- (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
{
_isSelectingSession = NO;