34 #define DRAGGING_WINDOW(anObject) ([anObject isKindOfClass:[CPWindow class]] ? anObject : [anObject window])
56 return [_CPDOMDataTransferPasteboard DOMDataTransferPasteboard];
70 - (CPPoint)draggingLocation
85 - (CGPoint)draggedImageLocation
95 - (CGPoint)draggedViewLocation
99 return [DRAGGING_WINDOW([dragServer draggingDestination]) convertPlatformWindowToBase:[[dragServer draggedView] frame].origin];
117 BOOL _isDraggingImage;
119 CGSize _draggingOffset;
124 unsigned _implementedDraggingSourceMethods;
126 CGPoint _draggingLocation;
127 id _draggingDestination;
128 BOOL _draggingDestinationWantsPeriodicUpdates;
130 CGPoint _startDragLocation;
131 BOOL _shouldSlideBack;
132 unsigned _dragOperation;
168 [_draggedWindow setLevel:CPDraggingWindowLevel];
174 - (id)draggingDestination
176 return _draggingDestination;
179 - (CGPoint)draggingLocation
181 return _draggingLocation
184 - (void)draggingStartedInPlatformWindow:(
CPPlatformWindow)aPlatformWindow globalLocation:(CGPoint)aLocation
186 if (_isDraggingImage)
188 if ([_draggingSource respondsToSelector:
@selector(draggedImage:beganAt:)])
189 [_draggingSource draggedImage:[_draggedView image] beganAt:aLocation];
193 if ([_draggingSource respondsToSelector:
@selector(draggedView:beganAt:)])
194 [_draggingSource draggedView:_draggedView beganAt:aLocation];
198 [_draggedWindow orderFront:self];
201 - (void)draggingSourceUpdatedWithGlobalLocation:(CGPoint)aGlobalLocation
204 [_draggedWindow setFrameOrigin:_CGPointMake(aGlobalLocation.x - _draggingOffset.width, aGlobalLocation.y - _draggingOffset.height)];
207 [_draggingSource draggedImage:[_draggedView image] movedTo:aGlobalLocation];
210 [_draggingSource draggedView:_draggedView movedTo:aGlobalLocation];
213 - (CPDragOperation)draggingUpdatedInPlatformWindow:(
CPPlatformWindow)aPlatformWindow location:(CGPoint)aLocation
215 [_draggingUpdateTimer invalidate];
216 _draggingUpdateTimer = nil;
220 draggingDestination = [aPlatformWindow _dragHitTest:aLocation pasteboard:[CPDragServerDraggingInfo draggingPasteboard]];
222 if (draggingDestination)
223 _draggingLocation = [DRAGGING_WINDOW(draggingDestination) convertPlatformWindowToBase:aLocation];
225 if (draggingDestination !== _draggingDestination)
227 if ([_draggingDestination respondsToSelector:
@selector(draggingExited:)])
228 [_draggingDestination draggingExited:CPDragServerDraggingInfo];
230 _draggingDestination = draggingDestination;
232 if ([_draggingDestination respondsToSelector:
@selector(wantsPeriodicDraggingUpdates)])
233 _draggingDestinationWantsPeriodicUpdates = [_draggingDestination wantsPeriodicDraggingUpdates];
235 _draggingDestinationWantsPeriodicUpdates = YES;
237 if ([_draggingDestination respondsToSelector:
@selector(draggingEntered:)])
238 dragOperation = [_draggingDestination draggingEntered:CPDragServerDraggingInfo];
240 else if ([_draggingDestination respondsToSelector:
@selector(draggingUpdated:)])
241 dragOperation = [_draggingDestination draggingUpdated:CPDragServerDraggingInfo];
243 if (!_draggingDestination)
247 if (_draggingDestinationWantsPeriodicUpdates)
251 userInfo:[
CPDictionary dictionaryWithJSObject:{platformWindow:aPlatformWindow, location:aLocation}]
254 var scrollView = [_draggingDestination isKindOfClass:[
CPView class]] ? [_draggingDestination enclosingScrollView] : nil;
257 var contentView = [scrollView contentView],
258 bounds = [contentView bounds],
259 insetBounds = CGRectInset(bounds, 30, 30),
260 eventLocation = [contentView convertPoint:_draggingLocation fromView:nil],
264 if (!CGRectContainsPoint(insetBounds, eventLocation))
266 if ([scrollView hasVerticalScroller])
268 if (eventLocation.y < _CGRectGetMinY(insetBounds))
269 deltaY = _CGRectGetMinY(insetBounds) - eventLocation.y;
270 else if (eventLocation.y > _CGRectGetMaxY(insetBounds))
271 deltaY = _CGRectGetMaxY(insetBounds) - eventLocation.y;
272 if (deltaY < -insetBounds.size.height)
273 deltaY = -insetBounds.size.height;
274 if (deltaY > insetBounds.size.height)
275 deltaY = insetBounds.size.height;
278 if ([scrollView hasHorizontalScroller])
280 if (eventLocation.x < _CGRectGetMinX(insetBounds))
281 deltaX = _CGRectGetMinX(insetBounds) - eventLocation.x;
282 else if (eventLocation.x > _CGRectGetMaxX(insetBounds))
283 deltaX = _CGRectGetMaxX(insetBounds) - eventLocation.x;
284 if (deltaX < -insetBounds.size.width)
285 deltaX = -insetBounds.size.width;
286 if (deltaX > insetBounds.size.width)
287 deltaX = insetBounds.size.width;
290 var scrollPoint = _CGPointMake(bounds.origin.x - deltaX, bounds.origin.y - deltaY);
292 [contentView scrollToPoint:scrollPoint];
293 [[scrollView _headerView] scrollPoint:scrollPoint];
299 return dragOperation;
302 - (void)_sendPeriodicDraggingUpdate:(
CPTimer)aTimer
305 _dragOperation = [
self draggingUpdatedInPlatformWindow:[userInfo objectForKey:@"platformWindow"]
306 location:[userInfo objectForKey:@"location"]];
309 - (void)draggingEndedInPlatformWindow:(
CPPlatformWindow)aPlatformWindow globalLocation:(CGPoint)aLocation operation:(CPDragOperation)anOperation
311 [_draggingUpdateTimer invalidate];
312 _draggingUpdateTimer = nil;
314 [_draggedView removeFromSuperview];
317 [_draggedWindow orderOut:self];
320 [_draggingSource draggedImage:[_draggedView image] endedAt:aLocation operation:anOperation];
322 [_draggingSource draggedView:_draggedView endedAt:aLocation operation:anOperation];
329 if (_draggingDestination &&
330 (![_draggingDestination respondsToSelector:
@selector(prepareForDragOperation:)] || [_draggingDestination prepareForDragOperation:
CPDragServerDraggingInfo]) &&
331 (![_draggingDestination respondsToSelector:
@selector(performDragOperation:)] || [_draggingDestination performDragOperation:
CPDragServerDraggingInfo]) &&
332 [_draggingDestination respondsToSelector:
@selector(concludeDragOperation:)])
333 [_draggingDestination concludeDragOperation:CPDragServerDraggingInfo];
348 - (void)dragView:(
CPView)aView fromWindow:(
CPWindow)aWindow at:(CGPoint)viewLocation offset:(CGSize)mouseOffset event:(
CPEvent)mouseDownEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
352 _draggedView = aView;
354 _draggingSource = aSourceObject;
355 _draggingDestination = nil;
356 _shouldSlideBack = slideBack;
360 var mouseDownWindow = [mouseDownEvent
window],
363 if (mouseDownEventLocation)
366 mouseDownEventLocation = [mouseDownWindow convertBaseToGlobal:mouseDownEventLocation];
368 _draggingOffset = _CGSizeMake(mouseDownEventLocation.x - viewLocation.x, mouseDownEventLocation.y - viewLocation.y);
371 _draggingOffset = _CGSizeMakeZero();
381 _startDragLocation = _CGPointMake(mouseLocation.x - _draggingOffset.width, mouseLocation.y - _draggingOffset.height);
382 [_draggedWindow setFrameOrigin:_startDragLocation];
383 [_draggedWindow setFrameSize:[aView
frame].size];
385 [[_draggedWindow contentView] addSubview:aView];
387 _implementedDraggingSourceMethods = 0;
389 if (_draggedView === _imageView)
391 if ([_draggingSource respondsToSelector:
@selector(draggedImage:movedTo:)])
394 if ([_draggingSource respondsToSelector:
@selector(draggedImage:endedAt:operation:)])
399 if ([_draggingSource respondsToSelector:
@selector(draggedView:movedTo:)])
402 if ([_draggingSource respondsToSelector:
@selector(draggedView:endedAt:operation:)])
425 - (void)dragImage:(
CPImage)anImage fromWindow:(
CPWindow)aWindow at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(
CPEvent)anEvent pasteboard:(
CPPasteboard)aPasteboard source:(
id)aSourceObject slideBack:(BOOL)slideBack
427 _isDraggingImage = YES;
429 var imageSize = [anImage
size];
432 _imageView = [[
CPImageView alloc] initWithFrame:_CGRectMake(0.0, 0.0, imageSize.width, imageSize.height)];
434 [_imageView setImage:anImage];
441 var type = [anEvent
type],
442 platformWindow = [_draggedWindow platformWindow],
473 [CPApp setTarget:self selector:@selector(trackDragging:)
474 forNextEventMatchingMask:CPMouseMovedMask | CPLeftMouseDraggedMask | CPLeftMouseUpMask | CPKeyDownMask
475 untilDate:nil inMode:0 dequeue:NO];
483 - (id)_dragHitTest:(CGPoint)aPoint pasteboard:(
CPPasteboard)aPasteboard
486 if (!_inclusiveRegisteredDraggedTypes)
496 hitView = [_windowView hitTest:adjustedPoint];
498 while (hitView && ![aPasteboard availableTypeFromArray:[hitView registeredDraggedTypes]])
499 hitView = [hitView superview];
504 if ([aPasteboard availableTypeFromArray:[
self registeredDraggedTypes]])
527 return _draggedWindow;
541 - (CGSize)draggingOffset
543 return _draggingOffset;
551 return _draggingPasteboard;
559 return _draggingSource;