Fix a lot of style issues.

Change a 1px value.
Closes #444.
This commit is contained in:
Ross Boucher
2010-02-15 21:27:27 -08:00
parent 62788423a1
commit 3e40deba5f
3 changed files with 92 additions and 63 deletions
+9 -6
View File
@@ -294,9 +294,12 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
tableColumn = [[_tableView tableColumns] objectAtIndex:_resizedColumn],
type = [anEvent type];
if (_lastLocation == nil) _lastLocation = location;
if (_columnOldWidth == nil) _columnOldWidth = [tableColumn width];
if (_lastLocation == nil)
_lastLocation = location;
if (_columnOldWidth == nil)
_columnOldWidth = [tableColumn width];
if (type === CPLeftMouseUp)
{
[self _updateResizeCursor:anEvent];
@@ -304,7 +307,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
[tableColumn _postDidResizeNotificationWithOldWidth:_columnOldWidth];
[tableColumn setDisableResizingPosting:NO];
[_tableView setDisableAutomaticResizing:NO];
_resizedColumn = -1;
_lastLocation = nil;
_columnOldWidth = nil;
@@ -327,13 +330,13 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
// We need to figure out the exact cocoa behavior here though.
//[_tableView resizeWithOldSuperviewSize:[_tableView bounds]];
_lastLocation = location;
[[CPCursor resizeLeftRightCursor] set];
[self setNeedsLayout];
[self setNeedsDisplay:YES];
}
}
[CPApp setTarget:self selector:@selector(trackResizeWithEvent:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
}
+77 -56
View File
@@ -126,8 +126,10 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
@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:
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
{
@@ -223,7 +225,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
_selectionHighlightMask = CPTableViewSelectionHighlightStyleRegular;
[self setUsesAlternatingRowBackgroundColors:NO];
[self setAlternatingRowBackgroundColors:[[CPColor whiteColor], /*[CPColor colorWithHexString:@"e4e7ff"]*/ [CPColor colorWithHexString:@"f5f9fc"]]];
[self setAlternatingRowBackgroundColors:[[CPColor whiteColor], [CPColor colorWithHexString:@"f5f9fc"]]];
_tableColumns = [];
_tableColumnRanges = [];
@@ -365,8 +367,10 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
//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.
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
{
@@ -747,7 +751,8 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
*/
- (void)selectRowIndexes:(CPIndexSet)rows byExtendingSelection:(BOOL)shouldExtendSelection
{
if ([rows isEqualToIndexSet:_selectedRowIndexes] || (([rows firstIndex] != CPNotFound && [rows firstIndex] < 0) || [rows lastIndex] >= [self numberOfRows]))
if ([rows isEqualToIndexSet:_selectedRowIndexes] ||
(([rows firstIndex] != CPNotFound && [rows firstIndex] < 0) || [rows lastIndex] >= [self numberOfRows]))
return;
// We deselect all columns when selecting rows.
@@ -1211,9 +1216,10 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
if(mask === CPTableViewUniformColumnAutoresizingStyle)
{
// FIX ME: needs to respect proportion of the the columns set width...
// this can also get slow when there are many rows
// do this by getting the width of the new size and subtracting it from the width of the old size dividing the difference by the number of visible rows.
// loop trough the rows one by one adding the quotient to each row be sure to check for min/max widths when doing it.
// this can also get slow when there are many rows do this by getting
// the width of the new size and subtracting it from the width of the old size dividing the
// difference by the number of visible rows. loop trough the rows one by one adding the quotient
// to each row be sure to check for min/max widths when doing it.
var superview = [self superview];
@@ -1317,7 +1323,9 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
/*!
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
@param aStyle The column autoresizing style for the receiver.
CPTableViewNoColumnAutoresizing, CPTableViewUniformColumnAutoresizingStyle,
CPTableViewLastColumnOnlyAutoresizingStyle, CPTableViewFirstColumnOnlyAutoresizingStyle
*/
- (void)setColumnAutoresizingStyle:(unsigned)style
{
@@ -1606,7 +1614,8 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
var startColumn = MIN(clickedColumn, [_selectedColumnIndexes lastIndex]),
endColumn = MAX(clickedColumn, [_selectedColumnIndexes firstIndex]);
[self selectColumnIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(startColumn, endColumn - startColumn + 1)] byExtendingSelection:YES];
[self selectColumnIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(startColumn, endColumn - startColumn + 1)]
byExtendingSelection:YES];
return;
}
@@ -1798,7 +1807,9 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
row = 0;
if(row >= [self numberOfRows] && operation === CPTableViewDropOn)
[[CPException exceptionWithName:@"Error" reason:@"Attempt to set dropRow="+ row +", dropOperation=CPTableViewDropOn when [0 - "+ [self numberOfRows] +"] is valid range of rows." userInfo:nil] raise];
[CPException raise:CPInvalidArgumentException
reason:@"Attempt to set dropRow="+ row +", dropOperation=CPTableViewDropOn when [0 - "+
[self numberOfRows] +"] is valid range of rows."];
_retargetedDropRow = row;
_retargetedDropOperation = operation;
@@ -2528,54 +2539,63 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
- (BOOL)continueTracking:(CGPoint)lastPoint at:(CGPoint)aPoint
{
var row = [self rowAtPoint: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
// 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 && _implementedDataSourceMethods & CPTableViewDataSource_tableView_writeRowsWithIndexes_toPasteboard_)
{
if (
(ABS(_startTrackingPoint.x - aPoint.x) > 4 || (_verticalMotionCanDrag && ABS(_startTrackingPoint.y - aPoint.y) > 4)) ||
([_selectedRowIndexes containsIndex:row])
)
if ((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] && [_dataSource tableView:self writeRowsWithIndexes:_draggedRowIndexes toPasteboard:pboard])
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] &&
[_dataSource tableView:self writeRowsWithIndexes:_draggedRowIndexes toPasteboard:pboard])
{
var currentEvent = [CPApp currentEvent],
offset = CPPointMakeZero(),
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 prefered 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 currentEvent = [CPApp currentEvent],
offset = CPPointMakeZero(),
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 prefered 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:CPMakeRect(0, 0, [image size].width, [image size].height)];
[view setImage:image];
}
var bounds = [view bounds];
var viewLocation = CPPointMake(aPoint.x - CGRectGetWidth(bounds)/2 + offset.x, aPoint.y - CGRectGetHeight(bounds)/2 + offset.y);
[self dragView:view at:viewLocation offset:CPPointMakeZero() event:[CPApp currentEvent] pasteboard:pboard source:self slideBack:YES];
_startTrackingPoint = nil;
return NO;
var image = [self dragImageForRowsWithIndexes:_draggedRowIndexes
tableColumns:tableColumns
event:currentEvent
offset:offset];
view = [[CPImageView alloc] initWithFrame:CPMakeRect(0, 0, [image size].width, [image size].height)];
[view setImage:image];
}
var bounds = [view bounds],
viewLocation = CPPointMake(aPoint.x - CGRectGetWidth(bounds)/2 + offset.x, aPoint.y - CGRectGetHeight(bounds)/2 + offset.y);
[self dragView:view
at:viewLocation
offset:CPPointMakeZero()
event:[CPApp currentEvent]
pasteboard:pboard
source:self
slideBack:YES];
_startTrackingPoint = nil;
return NO;
}
}
else if (ABS(_startTrackingPoint.x - aPoint.x) < 5 && ABS(_startTrackingPoint.y - aPoint.y) < 5)
return YES;
@@ -2802,7 +2822,8 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5;
[_dropOperationFeedbackView setCurrentRow:row];
[self addSubview:_dropOperationFeedbackView];
// FIXME : Maybe we should do this in a timer outside this method. Problem: we don't know when the scroll ends and neighter when the next -draggingUpdated is called. Which one will come first ?
// FIXME : Maybe we should do this in a timer outside this method.
// Problem: we don't know when the scroll ends or when the next -draggingUpdated is called.
if (row > 0 && location.y - CGRectGetMinY(exposedClipRect) < _rowHeight)
[self scrollRowToVisible:row - 1];
else if (row < numberOfRows && CGRectGetMaxY(exposedClipRect) - location.y < _rowHeight)
+6 -1
View File
@@ -162,7 +162,7 @@ CPLogRegister(CPLogConsole);
for (var i = 1; i <= 3; i++)
{
var column = [[CPTableColumn alloc] initWithIdentifier:String(i)];
[column setSortDescriptorPrototype:desc];
//[column setSortDescriptorPrototype:desc];
[[column headerView] setStringValue:"Number "+i];
[column setWidth:200.0];
@@ -384,6 +384,11 @@ CPLogRegister(CPLogConsole);
//for convenience
}
- (void)tableView:(CPTableView)aTableView didClickTableColumn:(CPTableColumn)aColumn
{
console.log("table: "+aTableView+" clicked column: "+aColumn);
}
@end
@implementation CPArray (MoveIndexes)