From 040e7bc9eeb0ca1e591de8cddcaf74d0e0f74351 Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Tue, 4 May 2010 12:06:06 +0200 Subject: [PATCH] - made the _dragViewForTableColumn:event:offset: method private - removed the multiple column support from _dragViewForTableColumn:event:offset: (Cocoa doesn't allow multiple column selection / dragging) - made the dragview the size of the dragged column --- AppKit/CPTableHeaderView.j | 12 ++---- AppKit/CPTableView.j | 77 +++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 48 deletions(-) diff --git a/AppKit/CPTableHeaderView.j b/AppKit/CPTableHeaderView.j index 444103e29..1b721d613 100644 --- a/AppKit/CPTableHeaderView.j +++ b/AppKit/CPTableHeaderView.j @@ -338,20 +338,14 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal if ([self _shouldDragTableColumn:aColumnIndex at:aPoint]) { - CPLog.debug(@"start drag"); - - var tableColumn = [[[self tableView] tableColumns] objectAtIndex:aColumnIndex], - columnRect = [self headerRectOfColumn:aColumnIndex]; - - var offset = CPPointMakeZero(), - view = [[self tableView] dragViewForTableColumns:[tableColumn] event:[CPApp currentEvent] offset:offset], + var columnRect = [self headerRectOfColumn:aColumnIndex], + offset = CPPointMakeZero(), + view = [[self tableView] _dragViewForColumn:aColumnIndex event:[CPApp currentEvent] offset:offset], viewLocation = CPPointMakeZero(); viewLocation.x = ( CPRectGetMinX(columnRect) + offset.x ) + ( aPoint.x - _mouseDownLocation.x ); viewLocation.y = CPRectGetMinY(columnRect) + offset.y; - [view setAlphaValue:0.7]; - [self dragView:view at:viewLocation offset:CPSizeMakeZero() event:[CPApp currentEvent] pasteboard:[CPPasteboard pasteboardWithName:CPDragPboard] source:self slideBack:YES]; diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 674a650dc..c9c5bc688 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -1846,52 +1846,51 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; return view; } -- (CPView)dragViewForTableColumns:(CPArray)theTableColumns event:(CPEvent)theDragEvent offset:(CPPointPointer)theDragViewOffset -{ - var bounds = CPRectMake(0.0, 0.0, 0.0, CPRectGetHeight([self bounds]) + 23.0); - index = [theTableColumns count], - dragView = [[CPView alloc] initWithFrame:CPRectMakeZero()]; - - // Fetch all the data views for the columns and visible rows - // After that copy these add them to a transparent drag view and use that drag view +/*! + @ignore + // Fetches all the data views (from the datasource) for the column and it's visible rows + // Copy the dataviews 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) - while (index--) +*/ +- (CPView)_dragViewForColumn:(int)theColumnIndex event:(CPEvent)theDragEvent offset:(CPPointPointer)theDragViewOffset +{ + var dragView = [[CPView alloc] initWithFrame:CPRectMakeZero()]; + tableColumn = [[self tableColumns] objectAtIndex:theColumnIndex], + bounds = CPRectMake(0.0, 0.0, [tableColumn width], CPRectGetHeight([self bounds]) + 23.0), + columnRect = [self rectOfColumn:theColumnIndex], + headerView = [tableColumn headerView]; + + // Add the column header view + var headerFrame = [headerView frame]; + headerFrame.origin = CPPointMakeZero(); + + columnHeaderView = [[_CPTableColumnHeaderView alloc] initWithFrame:headerFrame]; + [columnHeaderView setStringValue:[headerView stringValue]]; + [columnHeaderView setThemeState:[headerView themeState]]; + [dragView addSubview:columnHeaderView]; + + row = [_exposedRows firstIndex]; + while (row !== CPNotFound) { - // Get the tablecolumn and create a rect with it's width so we can use CPRectUnion - // to determine the end result - var tableColumn = [theTableColumns objectAtIndex:index], - columnIndex = [[self tableColumns] indexOfObjectIdenticalTo:tableColumn]; - columnRect = [self rectOfColumn:columnIndex], - headerView = [tableColumn headerView]; + var dataView = [self _newDataViewForRow:row tableColumn:tableColumn], + dataViewFrame = [self frameOfDataViewAtColumn:theColumnIndex row:row]; + + // Offset by table header height to make room for the table header + dataViewFrame.origin.x = 0.0; + dataViewFrame.origin.y += 23.0; + [dataView setFrame:dataViewFrame]; - // Add the column header view - columnHeaderView = [[_CPTableColumnHeaderView alloc] initWithFrame:[headerView frame]]; - [columnHeaderView setStringValue:[headerView stringValue]]; - [columnHeaderView setThemeState:[headerView themeState]]; - [dragView addSubview:columnHeaderView]; - - bounds = CPRectUnion(bounds, columnRect); + [dataView setObjectValue:[self _objectValueForTableColumn:tableColumn row:row]]; + [dragView addSubview:dataView]; - row = [_exposedRows firstIndex]; - while (row !== CPNotFound) - { - var dataView = [self _newDataViewForRow:row tableColumn:tableColumn], - dataViewFrame = [self frameOfDataViewAtColumn:columnIndex row:row]; - - // Offset by table header height to make room for the table header - dataViewFrame.origin.y += 23.0; - [dataView setFrame:dataViewFrame]; - - [dataView setObjectValue:[self _objectValueForTableColumn:tableColumn row:row]]; - [dragView addSubview:dataView]; - - row = [_exposedRows indexGreaterThanIndex:row]; - } + row = [_exposedRows indexGreaterThanIndex:row]; } // The columns are placed in the drag window at their original locations resulting in the dragged column - // being of when started the drag, we compensate for this by offseting the drag window by the x coordinate of the column - theDragViewOffset.x -= columnRect.origin.x; + // being of when starting the drag, we compensate for this by offseting the drag window by the x coordinate of the column + // theDragViewOffset.x -= columnRect.origin.x; + + [dragView setAlphaValue:0.7]; [dragView setFrame:bounds]; return dragView;