From 37fbeaad026479cf49319c7dc91c9fafdf234ff3 Mon Sep 17 00:00:00 2001 From: cacaodev Date: Mon, 25 Jan 2010 09:46:22 +0100 Subject: [PATCH 1/3] CPTableView -dragViewForRowsWithIndexes: - Change the way dragViewOffset is computed to conform to cocoa - Drag exposed rows only --- AppKit/CPTableView.j | 74 ++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 385a980ed..ef8b36f68 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -1445,8 +1445,8 @@ window.setTimeout(function(){ event:(CPEvent)theDragEvent offset:(CPPoint)dragViewOffset { - var size = [self bounds].size, - view = [[CPView alloc] initWithFrame:CPMakeRect(dragViewOffset.x, dragViewOffset.y, size.width, size.height)]; + var bounds = [self bounds], + view = [[CPView alloc] initWithFrame:bounds]; [view setBackgroundColor:[CPColor clearColor]]; [view setAlphaValue:0.7]; @@ -1455,32 +1455,40 @@ window.setTimeout(function(){ // 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) var firstExposedColumn = [_exposedColumns firstIndex], - exposedLength = [_exposedColumns lastIndex] - firstExposedColumn + 1, - columns = []; + firstExposedRow = [_exposedRows firstIndex], + exposedColumnsLength = [_exposedColumns lastIndex] - firstExposedColumn + 1, + exposedRowsLength = [_exposedRows lastIndex] - firstExposedRow + 1, + columns = [], + rows = []; - [_exposedColumns getIndexes:columns maxCount:-1 inIndexRange:CPMakeRange(firstExposedColumn, exposedLength)]; - - var columnIndex = [columns count], - draggedDataViews = [], - dragViewHeight = 0.0; + [_exposedColumns getIndexes:columns maxCount:-1 inIndexRange:CPMakeRange(firstExposedColumn, exposedColumnsLength)]; + [theDraggedRows getIndexes:rows maxCount:-1 inIndexRange:CPMakeRange(firstExposedRow, exposedRowsLength)]; + + var columnIndex = [columns count]; - while (columnIndex--) { - var column = [_tableColumns objectAtIndex:columnIndex], - yOffset = 0, - rowIndex = CPNotFound; + while (columnIndex--) + { + var column = columns[columnIndex], + tableColumn = [_tableColumns objectAtIndex:column], + rowIndex = [rows count]; - while ((rowIndex = [_selectedRowIndexes indexGreaterThanIndex:rowIndex]) !== CPNotFound) - { - var dataView = [self _newDataViewForRow:rowIndex tableColumn:column]; + while (rowIndex--) + { + var row = rows[rowIndex]; + var dataView = [self _newDataViewForRow:row tableColumn:tableColumn]; [dataView setBackgroundColor:[CPColor clearColor]]; - [dataView setFrame:[self frameOfDataViewAtColumn:columnIndex row:rowIndex]]; - [dataView setObjectValue:[self _objectValueForTableColumn:column row:rowIndex]]; + [dataView setFrame:[self frameOfDataViewAtColumn:column row:row]]; + [dataView setObjectValue:[self _objectValueForTableColumn:tableColumn row:row]]; [view addSubview:dataView]; } } + var dragPoint = [self convertPoint:[theDragEvent locationInWindow] fromView:nil]; + dragViewOffset.x = CGRectGetWidth(bounds)/2 - dragPoint.x; + dragViewOffset.y = CGRectGetHeight(bounds)/2 - dragPoint.y; + return view; } @@ -2155,10 +2163,8 @@ window.setTimeout(function(){ /* ignore */ - (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 if ( @@ -2170,7 +2176,7 @@ window.setTimeout(function(){ ) ) { - if([_selectedRowIndexes containsIndex:row]) + if ([_selectedRowIndexes containsIndex:row]) _draggedRowIndexes = [[CPIndexSet alloc] initWithIndexSet:_selectedRowIndexes]; else _draggedRowIndexes = [CPIndexSet indexSetWithIndex:row]; @@ -2179,32 +2185,34 @@ window.setTimeout(function(){ //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 ([self canDragRowsWithIndexes:_draggedRowIndexes atPoint:aPoint] && [_dataSource tableView:self writeRowsWithIndexes:_draggedRowIndexes toPasteboard:pboard]) { var currentEvent = [CPApp currentEvent], - offset = CPPointMakeZero(); + 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:_exposedColumns + tableColumns:tableColumns event:currentEvent - offset:CPPointMakeZero()]; + offset:offset]; - if (!view) { + if (!view) + { var image = [self dragImageForRowsWithIndexes:_draggedRowIndexes - tableColumns:_exposedColumns + tableColumns:tableColumns event:currentEvent - offset:CPPointMakeZero()]; - - view = [[CPImageView alloc] initWithFrame:CPMakeRect(aPoint.x, aPoint.y, [image size].width, [image size].height)]; + offset:offset]; + view = [[CPImageView alloc] initWithFrame:CPMakeRect(0, 0, [image size].width, [image size].height)]; [view setImage:image]; - - offset = aPoint; } - [self dragView:view at:offset offset:CPPointMakeZero() event:[CPApp currentEvent] pasteboard:pboard source:self slideBack:YES]; + 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]; + return NO; } } From df98483b065a61cdd3b941ce2d86e4c94bfd595b Mon Sep 17 00:00:00 2001 From: Derek Hammer Date: Wed, 27 Jan 2010 01:13:19 -0500 Subject: [PATCH 2/3] Removing extraneous selection did change notifications --- AppKit/CPTableView.j | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index ef8b36f68..1019bbe9b 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -658,6 +658,9 @@ window.setTimeout(function(){ { if (([rows firstIndex] != CPNotFound && [rows firstIndex] < 0) || [rows lastIndex] >= [self numberOfRows]) return; + + if ([rows isEqualToIndexSet:_selectedRowIndexes]) + return; // We deselect all columns when selecting rows. if ([_selectedColumnIndexes count] > 0) @@ -2261,10 +2264,6 @@ window.setTimeout(function(){ } } - if (![_previouslySelectedRowIndexes isEqualToIndexSet:_selectedRowIndexes]) - [self _noteSelectionDidChange]; - - if (mouseIsUp && (_implementedDataSourceMethods & CPTableViewDataSource_tableView_setObjectValue_forTableColumn_row_) && !_trackingPointMovedOutOfClickSlop @@ -2660,7 +2659,6 @@ window.setTimeout(function(){ if(i) { [self scrollRowToVisible:i]; - [self _noteSelectionDidChange]; } } @@ -2710,7 +2708,6 @@ window.setTimeout(function(){ if(i) { [self scrollRowToVisible:i]; - [self _noteSelectionDidChange]; } } From b9b2649db915683c58da2b6a4fb02dccddd425b7 Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Fri, 29 Jan 2010 01:37:57 -0500 Subject: [PATCH 3/3] Cleaned up merge and removed unnessisary selectionIsChanging notification. --- AppKit/CPTableView.j | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 1019bbe9b..ff105e47a 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -656,10 +656,7 @@ window.setTimeout(function(){ - (void)selectRowIndexes:(CPIndexSet)rows byExtendingSelection:(BOOL)shouldExtendSelection { - if (([rows firstIndex] != CPNotFound && [rows firstIndex] < 0) || [rows lastIndex] >= [self numberOfRows]) - return; - - if ([rows isEqualToIndexSet:_selectedRowIndexes]) + if ([rows isEqualToIndexSet:_selectedRowIndexes] || (([rows firstIndex] != CPNotFound && [rows firstIndex] < 0) || [rows lastIndex] >= [self numberOfRows])) return; // We deselect all columns when selecting rows. @@ -2578,8 +2575,6 @@ window.setTimeout(function(){ [self selectRowIndexes:newSelection byExtendingSelection:NO]; - [self _noteSelectionIsChanging]; - } - (void)_noteSelectionIsChanging