Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 72 lines (58 sloc) 1.988 kb
63de65f @uliwitness Added UKIsDragStart, a function to smartly detect whether a MouseDown ev...
authored
1 //
2 // UKIsDragStart.m
3 // Propaganda
4 //
5 // Created by Uli Kusterer on 01.05.10.
6 // Copyright 2010 Uli Kusterer. All rights reserved.
7 //
8
9 #import "UKIsDragStart.h"
10
3dda638 @uliwitness Distinguish horz/vert mouse moves in UKIsDragStart, useful for list view...
authored
11 #import <iso646.h>
12
63de65f @uliwitness Added UKIsDragStart, a function to smartly detect whether a MouseDown ev...
authored
13
14 UKIsDragStartResult UKIsDragStart( NSEvent *startEvent, NSTimeInterval theTimeout )
15 {
16 if( theTimeout == 0.0 )
17 theTimeout = 1.5;
18
19 NSPoint startPos = [startEvent locationInWindow];
20 NSTimeInterval startTime = [NSDate timeIntervalSinceReferenceDate];
21 NSDate* expireTime = [NSDate dateWithTimeIntervalSinceReferenceDate: startTime +theTimeout];
22
23 NSAutoreleasePool *pool = nil;
24 while( ([expireTime timeIntervalSinceReferenceDate] -[NSDate timeIntervalSinceReferenceDate]) > 0 )
25 {
8c71818 @uliwitness Oops. If we add all this pool code, we should also allocate one.
authored
26 [pool release];
27 pool = [[NSAutoreleasePool alloc] init];
63de65f @uliwitness Added UKIsDragStart, a function to smartly detect whether a MouseDown ev...
authored
28
29 NSEvent* currEvent = [NSApp nextEventMatchingMask: NSLeftMouseUpMask | NSRightMouseUpMask | NSOtherMouseUpMask
30 | NSLeftMouseDraggedMask | NSRightMouseDraggedMask | NSOtherMouseDraggedMask
31 untilDate: expireTime inMode: NSEventTrackingRunLoopMode dequeue: YES];
32 if( currEvent )
33 {
34 switch( [currEvent type] )
35 {
36 case NSLeftMouseUp:
37 case NSRightMouseUp:
38 case NSOtherMouseUp:
39 {
40 [pool release];
41 return UKIsDragStartMouseReleased; // Mouse released within the wait time.
42 break;
43 }
44
45 case NSLeftMouseDragged:
46 case NSRightMouseDragged:
47 case NSOtherMouseDragged:
48 {
49 NSPoint newPos = [currEvent locationInWindow];
3dda638 @uliwitness Distinguish horz/vert mouse moves in UKIsDragStart, useful for list view...
authored
50 CGFloat xMouseMovement = fabs(newPos.x -startPos.x),
51 yMouseMovement = abs(newPos.y -startPos.y);
52 if( xMouseMovement > 2 or yMouseMovement > 2 )
63de65f @uliwitness Added UKIsDragStart, a function to smartly detect whether a MouseDown ev...
authored
53 {
54 [pool release];
3dda638 @uliwitness Distinguish horz/vert mouse moves in UKIsDragStart, useful for list view...
authored
55 return (xMouseMovement > yMouseMovement) ? UKIsDragStartMouseMovedHorizontally : UKIsDragStartMouseMovedVertically; // Mouse moved within the wait time, probably a drag!
63de65f @uliwitness Added UKIsDragStart, a function to smartly detect whether a MouseDown ev...
authored
56 }
57 break;
58 }
87a2d32 @uliwitness Make this build with new SDK.
authored
59
60 default:
61 break;
63de65f @uliwitness Added UKIsDragStart, a function to smartly detect whether a MouseDown ev...
authored
62 }
63 }
64
65 }
66
67 [pool release];
68 return UKIsDragStartTimedOut; // If they held the mouse that long, they probably wanna drag.
69 }
70
71
Something went wrong with that request. Please try again.