From 76717c7177349c858bac857a9178925babb1bbd1 Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Fri, 22 Jan 2010 20:37:17 +0100 Subject: [PATCH 1/3] converted spaces to tabs --- AppKit/CPTableView.j | 222 +++++++++++++++++++++---------------------- 1 file changed, 111 insertions(+), 111 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 864945f13..ff6f6e56d 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -481,10 +481,10 @@ window.setTimeout(function(){ [self setSelectionHightlightColor:[CPColor selectionColorSourceView]]; _destinationDragStyle = CPTableViewDraggingDestinationFeedbackStyleSourceList; } - else - { - [self setSelectionHightlightColor:[CPColor selectionColor]]; - _destinationDragStyle = CPTableViewDraggingDestinationFeedbackStyleRegular; + else + { + [self setSelectionHightlightColor:[CPColor selectionColor]]; + _destinationDragStyle = CPTableViewDraggingDestinationFeedbackStyleRegular; } } @@ -1452,55 +1452,55 @@ window.setTimeout(function(){ } - (CPImage)dragImageForRowsWithIndexes:(CPIndexSet)dragRows - tableColumns:(CPArray)theTableColumns - event:(CPEvent)dragEvent - offset:(CPPointPointer)dragImageOffset + tableColumns:(CPArray)theTableColumns + event:(CPEvent)dragEvent + offset:(CPPointPointer)dragImageOffset { return [[CPImage alloc] initWithContentsOfFile:@"Frameworks/AppKit/Resources/GenericFile.png" size:CGSizeMake(32,32)]; } - (CPView)dragViewForRowsWithIndexes:(CPIndexSet)theDraggedRows - tableColumns:(CPArray)theTableColumns - event:(CPEvent)theDragEvent - offset:(CPPoint)dragViewOffset + tableColumns:(CPArray)theTableColumns + event:(CPEvent)theDragEvent + offset:(CPPoint)dragViewOffset { - var size = [self bounds].size, - view = [[CPView alloc] initWithFrame:CPMakeRect(dragViewOffset.x, dragViewOffset.y, size.width, size.height)]; - - [view setBackgroundColor:[CPColor clearColor]]; - [view setAlphaValue:0.7]; - - // 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) - var firstExposedColumn = [_exposedColumns firstIndex], - exposedLength = [_exposedColumns lastIndex] - firstExposedColumn + 1, - columns = []; - - [_exposedColumns getIndexes:columns maxCount:-1 inIndexRange:CPMakeRange(firstExposedColumn, exposedLength)]; - - var columnIndex = [columns count], - draggedDataViews = [], - dragViewHeight = 0.0; - - while (columnIndex--) { - var column = [_tableColumns objectAtIndex:columnIndex], - yOffset = 0, - rowIndex = CPNotFound; - - while ((rowIndex = [_selectedRowIndexes indexGreaterThanIndex:rowIndex]) !== CPNotFound) - { - var dataView = [self _newDataViewForRow:rowIndex tableColumn:column]; - - [dataView setBackgroundColor:[CPColor clearColor]]; - [dataView setFrame:[self frameOfDataViewAtColumn:columnIndex row:rowIndex]]; - [dataView setObjectValue:[self _objectValueForTableColumn:column row:rowIndex]]; - - [view addSubview:dataView]; - } - } - - return view; + var size = [self bounds].size, + view = [[CPView alloc] initWithFrame:CPMakeRect(dragViewOffset.x, dragViewOffset.y, size.width, size.height)]; + + [view setBackgroundColor:[CPColor clearColor]]; + [view setAlphaValue:0.7]; + + // 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) + var firstExposedColumn = [_exposedColumns firstIndex], + exposedLength = [_exposedColumns lastIndex] - firstExposedColumn + 1, + columns = []; + + [_exposedColumns getIndexes:columns maxCount:-1 inIndexRange:CPMakeRange(firstExposedColumn, exposedLength)]; + + var columnIndex = [columns count], + draggedDataViews = [], + dragViewHeight = 0.0; + + while (columnIndex--) { + var column = [_tableColumns objectAtIndex:columnIndex], + yOffset = 0, + rowIndex = CPNotFound; + + while ((rowIndex = [_selectedRowIndexes indexGreaterThanIndex:rowIndex]) !== CPNotFound) + { + var dataView = [self _newDataViewForRow:rowIndex tableColumn:column]; + + [dataView setBackgroundColor:[CPColor clearColor]]; + [dataView setFrame:[self frameOfDataViewAtColumn:columnIndex row:rowIndex]]; + [dataView setObjectValue:[self _objectValueForTableColumn:column row:rowIndex]]; + + [view addSubview:dataView]; + } + } + + return view; } - (void)setDraggingSourceOperationMask:(CPDragOperation)mask forLocal:(BOOL)isLocal @@ -1573,7 +1573,7 @@ window.setTimeout(function(){ - (id)_objectValueForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex { - CPLog.debug(@"_objectValueForTableColumn:%@ row: %@", aTableColumn, aRowIndex); + CPLog.debug(@"_objectValueForTableColumn:%@ row: %@", aTableColumn, aRowIndex); var tableColumnUID = [aTableColumn UID], tableColumnObjectValues = _objectValues[tableColumnUID]; @@ -1591,7 +1591,7 @@ window.setTimeout(function(){ tableColumnObjectValues[aRowIndex] = objectValue; } - CPLog.debug(@"return %@", objectValue); + CPLog.debug(@"return %@", objectValue); return objectValue; } @@ -1991,7 +1991,7 @@ window.setTimeout(function(){ indexes = [], rectSelector = @selector(rectOfRow:); - [_selectionHightlightColor setFill]; + [_selectionHightlightColor setFill]; if ([_selectedRowIndexes count] >= 1) @@ -2201,30 +2201,30 @@ window.setTimeout(function(){ if([self canDragRowsWithIndexes:_draggedRowIndexes atPoint:aPoint] && [_dataSource tableView:self writeRowsWithIndexes:_draggedRowIndexes toPasteboard:pboard]) { - var currentEvent = [CPApp currentEvent], - offset = CPPointMakeZero(); - - // 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 - event:currentEvent - offset:CPPointMakeZero()]; - - if (!view) { - var image = [self dragImageForRowsWithIndexes:_draggedRowIndexes - tableColumns:_exposedColumns - event:currentEvent - offset:CPPointMakeZero()]; - - view = [[CPImageView alloc] initWithFrame:CPMakeRect(aPoint.x, aPoint.y, [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 currentEvent = [CPApp currentEvent], + offset = CPPointMakeZero(); + + // 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 + event:currentEvent + offset:CPPointMakeZero()]; + + if (!view) { + var image = [self dragImageForRowsWithIndexes:_draggedRowIndexes + tableColumns:_exposedColumns + event:currentEvent + offset:CPPointMakeZero()]; + + view = [[CPImageView alloc] initWithFrame:CPMakeRect(aPoint.x, aPoint.y, [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]; return NO; } } @@ -2595,32 +2595,32 @@ window.setTimeout(function(){ var anEvent = [events objectAtIndex:i], key = [anEvent keyCode]; - if(key === CPDeleteKeyCode && [_delegate respondsToSelector: @selector(tableViewDeleteKeyPressed:)]) + if(key === CPDeleteKeyCode && [_delegate respondsToSelector: @selector(tableViewDeleteKeyPressed:)]) [_delegate tableViewDeleteKeyPressed:self]; - if(key === CPUpArrowKeyCode) - { - if([[self selectedRowIndexes] count] > 0) - { - var extend = NO; + if(key === CPUpArrowKeyCode) + { + if([[self selectedRowIndexes] count] > 0) + { + var extend = NO; - if(([anEvent modifierFlags] & CPShiftKeyMask) && _allowsMultipleSelection) + if(([anEvent modifierFlags] & CPShiftKeyMask) && _allowsMultipleSelection) extend = YES; - var i = [[self selectedRowIndexes] firstIndex]; - if(i > 0) - i--; //set index to the prev row before the first row selected - } + var i = [[self selectedRowIndexes] firstIndex]; + if(i > 0) + i--; //set index to the prev row before the first row selected + } else - { - var extend = NO; - //no rows are currently selected - if([self numberOfRows] > 0) - var i = [self numberOfRows] - 1; //select the first row - } + { + var extend = NO; + //no rows are currently selected + if([self numberOfRows] > 0) + var i = [self numberOfRows] - 1; //select the first row + } - if(_implementedDelegateMethods & CPTableViewDelegate_tableView_shouldSelectRow_) + if(_implementedDelegateMethods & CPTableViewDelegate_tableView_shouldSelectRow_) { while((![_delegate tableView:self shouldSelectRow:i]) && i > 0) @@ -2641,31 +2641,31 @@ window.setTimeout(function(){ [self scrollRowToVisible:i]; [self _noteSelectionDidChange]; } - } + } - if(key == CPDownArrowKeyCode) - { - if([[self selectedRowIndexes] count] > 0) - { - var extend = NO; + if(key == CPDownArrowKeyCode) + { + if([[self selectedRowIndexes] count] > 0) + { + var extend = NO; - if(([anEvent modifierFlags] & CPShiftKeyMask) && _allowsMultipleSelection) + if(([anEvent modifierFlags] & CPShiftKeyMask) && _allowsMultipleSelection) extend = YES; - var i = [[self selectedRowIndexes] lastIndex]; - if(i<[self numberOfRows] - 1) - i++; //set index to the next row after the last row selected - } + var i = [[self selectedRowIndexes] lastIndex]; + if(i<[self numberOfRows] - 1) + i++; //set index to the next row after the last row selected + } else - { - var extend = NO; - //no rows are currently selected - if([self numberOfRows] > 0) - var i = 0; //select the first row - } + { + var extend = NO; + //no rows are currently selected + if([self numberOfRows] > 0) + var i = 0; //select the first row + } - if(_implementedDelegateMethods & CPTableViewDelegate_tableView_shouldSelectRow_) + if(_implementedDelegateMethods & CPTableViewDelegate_tableView_shouldSelectRow_) { while((![_delegate tableView:self shouldSelectRow:i]) && i<[self numberOfRows]) @@ -2686,7 +2686,7 @@ window.setTimeout(function(){ [self scrollRowToVisible:i]; [self _noteSelectionDidChange]; } - } + } } } From e09b63183c4475d310a1a17041d6555e4d897586 Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Fri, 22 Jan 2010 20:44:58 +0100 Subject: [PATCH 2/3] added cpviewanimation --- AppKit/CPViewAnimation.j | 184 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 AppKit/CPViewAnimation.j diff --git a/AppKit/CPViewAnimation.j b/AppKit/CPViewAnimation.j new file mode 100644 index 000000000..5950d9609 --- /dev/null +++ b/AppKit/CPViewAnimation.j @@ -0,0 +1,184 @@ +/* + * CPViewAnimation.j + * + * Created by Klaas Pieter Annema on September 3, 2009. + * Copyright 2009, Sofa BV + */ + + +@import + +CPViewAnimationTargetKey = @"CPViewAnimationTarget"; +CPViewAnimationStartFrameKey = @"CPViewAnimationStartFrame"; +CPViewAnimationEndFrameKey = @"CPViewAnimationEndFrame"; +CPViewAnimationEffectKey = @"CPViewAnimationEffect"; + +CPViewAnimationFadeInEffect = @"CPViewAnimationFadeIn"; +CPViewAnimationFadeOutEffect = @"CPViewAnimationFadeOut"; + +@implementation CPViewAnimation : CPAnimation +{ + CPArray _viewAnimations; +} + +- (id)initWithViewAnimations:(CPArray)viewAnimations +{ + if(self = [super initWithDuration:0.5 animationCurve:CPAnimationLinear]) + { + [self setViewAnimations:viewAnimations]; + } + return self; +} + +// ============= +// = ANIMATION = +// ============= +- (void)startAnimation +{ + var animationIndex = [_viewAnimations count]; + + while (animationIndex--) + { + var dictionary = [_viewAnimations objectAtIndex:animationIndex]; + + var view = [self _targetView:dictionary], + startFrame = [self _startFrame:dictionary]; + + [view setFrame:startFrame]; + + var effect = [self _effect:dictionary]; + + if (effect === CPViewAnimationFadeInEffect) + { + [view setAlphaValue:0.0]; + [view setHidden:NO]; + } + else if (effect === CPViewAnimationFadeOutEffect) + [view setAlphaValue:1.0]; + } + + [super startAnimation]; +} + +- (void)setCurrentProgress:(NSAnimationProgress)progress +{ + [super setCurrentProgress:progress]; + + var animationIndex = [_viewAnimations count]; + while (animationIndex--) + { + var dictionary = [_viewAnimations objectAtIndex:animationIndex]; + + // Update the view's frame + var view = [self _targetView:dictionary] + startFrame = [self _startFrame:dictionary] + endFrame = [self _endFrame:dictionary] + differenceFrame = CPRectMakeZero(); + + differenceFrame.origin.x = endFrame.origin.x - startFrame.origin.x; + differenceFrame.origin.y = endFrame.origin.y - startFrame.origin.y; + differenceFrame.size.width = endFrame.size.width - startFrame.size.width; + differenceFrame.size.height = endFrame.size.height - startFrame.size.height; + + var intermediateFrame = CPRectMakeZero(); + intermediateFrame.origin.x = startFrame.origin.x + differenceFrame.origin.x * progress; + intermediateFrame.origin.y = startFrame.origin.y + differenceFrame.origin.y * progress; + intermediateFrame.size.width = startFrame.size.width + differenceFrame.size.width * progress; + intermediateFrame.size.height = startFrame.size.height + differenceFrame.size.height * progress; + + [view setFrame:intermediateFrame]; + + // Update the view's alpha value + var effect = [self _effect:dictionary]; + + if (effect === CPViewAnimationFadeInEffect) + [view setAlphaValue:1.0 * progress]; + else if (effect === CPViewAnimationFadeOutEffect) + [view setAlphaValue:1.0 + ( 0.0 - 1.0 ) * progress]; + + if (progress === 1.0) + [view setHidden:CPRectIsNull(endFrame) || [view alphaValue] === 0.0]; + } +} + +- (void)stopAnimation +{ + var animationIndex = [_viewAnimations count]; + while (animationIndex--) + { + var dictionary = [_viewAnimations objectAtIndex:animationIndex]; + + var view = [self _targetView:dictionary], + endFrame = [self _endFrame:dictionary]; + + [view setFrame:endFrame]; + + var effect = [self _effect:dictionary]; + + if (effect === CPViewAnimationFadeInEffect) + [view setAlphaValue:1.0]; + else if (effect === CPViewAnimationFadeOutEffect) + [view setAlphaValue:0.0]; + + [view setHidden:CPRectIsNull(endFrame) || [view alphaValue] === 0.0]; + } + + [super stopAnimation]; +} + +// =============== +// = CONVENIENCE = +// =============== +- (id)_targetView:(CPDictionary)dictionary +{ + var targetView = [dictionary valueForKey:CPViewAnimationTargetKey]; + + if (!targetView) + [CPException raise:CPInternalInconsistencyException reason:[CPString stringWithFormat:@"view animation: %@ does not have a target view", [dictionary description]]]; + + return targetView; +} + +- (CPRect)_startFrame:(CPDictionary)dictionary +{ + var startFrame = [dictionary valueForKey:CPViewAnimationStartFrameKey]; + + if (!startFrame) + return [[self _targetView:dictionary] frame]; + + return startFrame; +} + +- (CPRect)_endFrame:(CPDictionary)dictionary +{ + var endFrame = [dictionary valueForKey:CPViewAnimationEndFrameKey]; + + if (!endFrame) + return [[self _targetView:dictionary] frame]; + + return endFrame; +} + +- (CPString)_effect:(CPDictionary)dictionary +{ + return [dictionary valueForKey:CPViewAnimationEffectKey]; +} + +// ============= +// = ACCESSORS = +// ============= +- (CPArray)viewAnimations +{ + return _viewAnimations; +} + +- (void)setViewAnimations:(CPArray)viewAnimations +{ + if (viewAnimations != _viewAnimations) + { + [self stopAnimation]; + _viewAnimations = [viewAnimations copy]; + } +} + +@end From 78083eea4889d1540361b0f87c200217b8e6c694 Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Fri, 29 Jan 2010 12:14:08 +0100 Subject: [PATCH 3/3] made sure CPControl's trackMouse: doesn't eat mouse events when the tableview is in a drag session #431 --- AppKit/CPTableView.j | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index ff105e47a..de4397fc3 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -2160,6 +2160,15 @@ window.setTimeout(function(){ return YES; } +- (void)trackMouse:(CPEvent)anEvent +{ + // Prevent CPControl from eating the mouse events when we are in a drag session + if (![_draggedRowIndexes count]) + [super trackMouse:anEvent]; + else + [CPApp sendEvent:anEvent]; +} + /* ignore */ - (BOOL)continueTracking:(CGPoint)lastPoint at:(CGPoint)aPoint {