27 #define DRAGGING_WINDOW(anObject) ([anObject isKindOfClass:[CPWindow class]] ? anObject : [anObject window]) 49 return [_CPDOMDataTransferPasteboard DOMDataTransferPasteboard];
63 - (CGPoint)draggingLocation
78 - (CGPoint)draggedImageLocation
88 - (CGPoint)draggedViewLocation
92 return [DRAGGING_WINDOW([dragServer draggingDestination]) convertPlatformWindowToBase:[[dragServer draggedView] frame].origin];
110 BOOL _isDraggingImage;
112 CGSize _draggingOffset;
117 unsigned _implementedDraggingSourceMethods;
119 CGPoint _draggingLocation;
120 id _draggingDestination;
121 BOOL _draggingDestinationWantsPeriodicUpdates;
123 CGPoint _startDragLocation;
124 BOOL _shouldSlideBack;
125 unsigned _dragOperation;
161 [_draggedWindow setLevel:CPDraggingWindowLevel];
167 - (id)draggingDestination
169 return _draggingDestination;
172 - (CGPoint)draggingLocation
174 return _draggingLocation
177 - (void)draggingStartedInPlatformWindow:(
CPPlatformWindow)aPlatformWindow globalLocation:(CGPoint)aLocation
179 if (_isDraggingImage)
181 if ([_draggingSource respondsToSelector:
@selector(draggedImage:beganAt:)])
182 [_draggingSource draggedImage:[_draggedView image] beganAt:aLocation];
186 if ([_draggingSource respondsToSelector:
@selector(draggedView:beganAt:)])
187 [_draggingSource draggedView:_draggedView beganAt:aLocation];
191 [_draggedWindow orderFront:self];
194 - (void)draggingSourceUpdatedWithGlobalLocation:(CGPoint)aGlobalLocation
198 var
frame = [_draggedWindow frame];
199 frame.origin.x = aGlobalLocation.x - _draggingOffset.width;
200 frame.origin.y = aGlobalLocation.y - _draggingOffset.height;
201 [_draggedWindow _setFrame:frame display:YES animate:NO constrainWidth:NO constrainHeight:NO];
205 [_draggingSource draggedImage:[_draggedView image] movedTo:aGlobalLocation];
208 [_draggingSource draggedView:_draggedView movedTo:aGlobalLocation];
211 - (CPDragOperation)draggingUpdatedInPlatformWindow:(
CPPlatformWindow)aPlatformWindow location:(CGPoint)aLocation
213 [_draggingUpdateTimer invalidate];
214 _draggingUpdateTimer = nil;
218 draggingDestination = [aPlatformWindow _dragHitTest:aLocation pasteboard:[CPDragServerDraggingInfo draggingPasteboard]];
220 if (draggingDestination)
221 _draggingLocation = [DRAGGING_WINDOW(draggingDestination) convertPlatformWindowToBase:aLocation];
223 if (draggingDestination !== _draggingDestination)
225 if ([_draggingDestination respondsToSelector:
@selector(draggingExited:)])
226 [_draggingDestination draggingExited:CPDragServerDraggingInfo];
228 _draggingDestination = draggingDestination;
230 if ([_draggingDestination respondsToSelector:
@selector(wantsPeriodicDraggingUpdates)])
231 _draggingDestinationWantsPeriodicUpdates = [_draggingDestination wantsPeriodicDraggingUpdates];
233 _draggingDestinationWantsPeriodicUpdates = YES;
235 if ([_draggingDestination respondsToSelector:
@selector(draggingEntered:)])
236 dragOperation = [_draggingDestination draggingEntered:CPDragServerDraggingInfo];
238 else if ([_draggingDestination respondsToSelector:
@selector(draggingUpdated:)])
239 dragOperation = [_draggingDestination draggingUpdated:CPDragServerDraggingInfo];
241 if (!_draggingDestination)
245 if (_draggingDestinationWantsPeriodicUpdates)
249 userInfo:@{ "platformWindow":aPlatformWindow, "location":aLocation }
252 var scrollView = [_draggingDestination isKindOfClass:[
CPView class]] ? [_draggingDestination enclosingScrollView] : nil;
255 var contentView = [scrollView contentView],
256 bounds = [contentView bounds],
257 insetBounds = CGRectInset(
bounds, 30, 30),
258 eventLocation = [contentView convertPoint:_draggingLocation fromView:nil],
262 if (!CGRectContainsPoint(insetBounds, eventLocation))
264 if ([scrollView hasVerticalScroller])
266 if (eventLocation.y < CGRectGetMinY(insetBounds))
267 deltaY = CGRectGetMinY(insetBounds) - eventLocation.y;
268 else if (eventLocation.y > CGRectGetMaxY(insetBounds))
269 deltaY = CGRectGetMaxY(insetBounds) - eventLocation.y;
270 if (deltaY < -insetBounds.size.height)
271 deltaY = -insetBounds.size.height;
272 if (deltaY > insetBounds.size.height)
273 deltaY = insetBounds.size.height;
276 if ([scrollView hasHorizontalScroller])
278 if (eventLocation.x < CGRectGetMinX(insetBounds))
279 deltaX = CGRectGetMinX(insetBounds) - eventLocation.x;
280 else if (eventLocation.x > CGRectGetMaxX(insetBounds))
281 deltaX = CGRectGetMaxX(insetBounds) - eventLocation.x;
282 if (deltaX < -insetBounds.size.width)
283 deltaX = -insetBounds.size.width;
284 if (deltaX > insetBounds.size.width)
285 deltaX = insetBounds.size.width;
288 var scrollPoint = CGPointMake(
bounds.origin.x - deltaX,
bounds.origin.y - deltaY);
290 [contentView scrollToPoint:scrollPoint];
291 [[scrollView _headerView] scrollPoint:scrollPoint];
297 return dragOperation;
300 - (void)_sendPeriodicDraggingUpdate:(
CPTimer)aTimer
303 _dragOperation = [
self draggingUpdatedInPlatformWindow:[userInfo objectForKey:@"platformWindow"]
304 location:[userInfo objectForKey:@"location"]];
307 - (void)draggingEndedInPlatformWindow:(
CPPlatformWindow)aPlatformWindow globalLocation:(CGPoint)aLocation operation:(CPDragOperation)anOperation
309 [_draggingUpdateTimer invalidate];
310 _draggingUpdateTimer = nil;
312 [_draggedView removeFromSuperview];
315 [_draggedWindow orderOut:self];
318 [_draggingSource draggedImage:[_draggedView image] endedAt:aLocation operation:anOperation];
320 [_draggingSource draggedView:_draggedView endedAt:aLocation operation:anOperation];
327 if (_draggingDestination &&
328 (![_draggingDestination respondsToSelector:
@selector(prepareForDragOperation:)] || [_draggingDestination prepareForDragOperation:
CPDragServerDraggingInfo]) &&
329 (![_draggingDestination respondsToSelector:
@selector(performDragOperation:)] || [_draggingDestination performDragOperation:
CPDragServerDraggingInfo]) &&
330 [_draggingDestination respondsToSelector:
@selector(concludeDragOperation:)])
331 [_draggingDestination concludeDragOperation:CPDragServerDraggingInfo];
346 - (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
350 _draggedView = aView;
352 _draggingSource = aSourceObject;
353 _draggingDestination = nil;
354 _shouldSlideBack = slideBack;
358 var mouseDownWindow = [mouseDownEvent
window],
361 if (mouseDownEventLocation)
364 mouseDownEventLocation = [mouseDownWindow convertBaseToGlobal:mouseDownEventLocation];
366 _draggingOffset = CGSizeMake(mouseDownEventLocation.x - viewLocation.x, mouseDownEventLocation.y - viewLocation.y);
369 _draggingOffset = CGSizeMakeZero();
378 startDragLocationX = mouseLocation.x - _draggingOffset.width,
379 startDragLocationY = mouseLocation.y - _draggingOffset.height,
380 draggedWindowFrame = CGRectMake(startDragLocationX, startDragLocationY, viewSize.width, viewSize.height);
383 _startDragLocation = CGPointMake(startDragLocationX, startDragLocationY);
385 [_draggedWindow _setFrame:draggedWindowFrame display:YES animate:NO constrainWidth:NO constrainHeight:NO];
387 [[_draggedWindow contentView] addSubview:aView];
389 _implementedDraggingSourceMethods = 0;
391 if (_draggedView === _imageView)
393 if ([_draggingSource respondsToSelector:
@selector(draggedImage:movedTo:)])
396 if ([_draggingSource respondsToSelector:
@selector(draggedImage:endedAt:operation:)])
401 if ([_draggingSource respondsToSelector:
@selector(draggedView:movedTo:)])
404 if ([_draggingSource respondsToSelector:
@selector(draggedView:endedAt:operation:)])
427 - (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
429 _isDraggingImage = YES;
431 var imageSize = [anImage
size];
434 _imageView = [[
CPImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, imageSize.width, imageSize.height)];
436 [_imageView setImage:anImage];
443 var type = [anEvent
type],
444 platformWindow = [_draggedWindow platformWindow],
476 [CPApp setTarget:self selector:@selector(trackDragging:)
477 forNextEventMatchingMask:CPMouseMovedMask | CPLeftMouseDraggedMask | CPLeftMouseUpMask | CPKeyDownMask
478 untilDate:nil inMode:0 dequeue:YES];
498 return _draggedWindow;
512 - (CGSize)draggingOffset
514 return _draggingOffset;
522 return _draggingPasteboard;
530 return _draggingSource;
CGPoint draggingLocation()
CGPoint convertBaseToPlatformWindow:(CGPoint aPoint)
CPPasteboard draggingPasteboard()
CPDragOperation CPDragOperationNone
var CPDragServerDraggingInfo
CGPoint locationInWindow()
void trackDragging:(CPEvent anEvent)
CGPoint draggedViewLocation()
void draggingStartedInPlatformWindow:globalLocation:(CPPlatformWindow aPlatformWindow, [globalLocation] CGPoint aLocation)
#define DRAGGING_WINDOW(anObject)
var CPDragServerPreviousEvent
id initWithContentRect:styleMask:(CGRect aContentRect, [styleMask] unsigned aStyleMask)
void draggingSourceUpdatedWithGlobalLocation:(CGPoint aGlobalLocation)
var CPDragServerPeriodicUpdateInterval
CPDragServer sharedDragServer()
var CPDraggingSource_draggedImage_movedTo_
void dragView:fromWindow:at:offset:event:pasteboard:source:slideBack:(CPView aView, [fromWindow] CPWindow aWindow, [at] CGPoint viewLocation, [offset] CGSize mouseOffset, [event] CPEvent mouseDownEvent, [pasteboard] CPPasteboard aPasteboard, [source] id aSourceObject, [slideBack] BOOL slideBack)
CPTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:(CPTimeInterval seconds, [target] id aTarget, [selector] SEL aSelector, [userInfo] id userInfo, [repeats] BOOL shouldRepeat)
void performDragOperationInPlatformWindow:(CPPlatformWindow aPlatformWindow)
var CPDraggingSource_draggedView_endedAt_operation_
A timer object that can send a message after the given time interval.
var CPDraggingSource_draggedView_movedTo_
var CPDraggingSource_draggedImage_endedAt_operation_
void draggingEndedInPlatformWindow:globalLocation:operation:(CPPlatformWindow aPlatformWindow, [globalLocation] CGPoint aLocation, [operation] CPDragOperation anOperation)
CPPlatformWindow platformWindow()
CPDragOperation draggingUpdatedInPlatformWindow:location:(CPPlatformWindow aPlatformWindow, [location] CGPoint aLocation)
void setFrameOrigin:(CGPoint aPoint)
id pasteboardWithName:(CPString aName)