-
Notifications
You must be signed in to change notification settings - Fork 11
/
TSDelegatingDropZoneView.m
96 lines (78 loc) · 2.37 KB
/
TSDelegatingDropZoneView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// TSDelegatingDropZoneView.m
// ThisService
//
// Created by Jesper on 2011-07-25.
// Copyright 2011-2012 waffle software. All rights reserved.
// BSD licensed - see license.txt for more information.
//
#import "TSDelegatingDropZoneView.h"
@implementation TSDelegatingDropZoneView
- (void)setDraggingDestination:(NSView *)aDraggingDestination {
[self unregisterDraggedTypes];
draggingDestination = aDraggingDestination;
[self registerForDraggedTypes:[draggingDestination registeredDraggedTypes]];
}
- (NSView *)draggingDestination {
return draggingDestination;
}
- (void)setDropHovering:(BOOL)dh {
if (dh != drophovering) {
drophovering = dh;
[self setNeedsDisplay:YES];
}
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
NSDragOperation operation = [draggingDestination draggingEntered:sender];
[self setDropHovering:(operation != NSDragOperationNone)];
return operation;
}
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender {
NSDragOperation operation = [draggingDestination draggingUpdated:sender];
[self setDropHovering:(operation != NSDragOperationNone)];
return operation;
}
- (void)draggingEnded:(id <NSDraggingInfo>)sender {
if ([draggingDestination respondsToSelector:@selector(draggingEnded:)]) {
[draggingDestination draggingEnded:sender];
}
[self setDropHovering:NO];
}
- (void)draggingExited:(id <NSDraggingInfo>)sender {
[draggingDestination draggingExited:sender];
[self setDropHovering:NO];
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
BOOL result = [draggingDestination performDragOperation:sender];
[self setDropHovering:result];
return result;
}
- (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender {
BOOL result = [draggingDestination prepareForDragOperation:sender];
[self setDropHovering:result];
return result;
}
- (BOOL)wantsPeriodicDraggingUpdates {
return YES;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender {
[draggingDestination concludeDragOperation:sender];
[self setDropHovering:NO];
}
- (BOOL)isOpaque {
return NO;
}
- (void)drawRect:(NSRect)rect {
if (drophovering) {
if (!NSEqualSizes(rect.size,[self frame].size)) {
[self setNeedsDisplay:YES];
return;
}
[[NSColor selectedControlColor] setStroke];
} else {
[[NSColor clearColor] setStroke];
}
[NSBezierPath strokeRect:rect];
[NSBezierPath strokeRect:NSInsetRect(rect,1.0,1.0)];
}
@end