forked from belkadan/Webmailer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DropOverlayView.m
65 lines (51 loc) · 1.55 KB
/
DropOverlayView.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
#import "DropOverlayView.h"
#import <QuartzCore/QuartzCore.h>
static const double kBlurRadius = 1.0;
@interface ComBelkadanUtils_DropOverlayView ()
- (void)show;
- (void)hide;
@end
@implementation ComBelkadanUtils_DropOverlayView
@synthesize delegate;
- (void)awakeFromNib {
[self retain];
NSView *superview = [self superview];
[self removeFromSuperview];
[superview addSubview:self positioned:NSWindowAbove relativeTo:nil];
[self release];
if ([delegate respondsToSelector:@selector(dragTypesForDropOverlayView:)]) {
[self registerForDraggedTypes:[delegate dragTypesForDropOverlayView:self]];
}
}
- (void)show {
[self setAlphaValue:1];
CIFilter *blur = [CIFilter filterWithName:@"CIGaussianBlur"];
[blur setValue:[NSNumber numberWithDouble:kBlurRadius] forKey:@"inputRadius"];
[blur setValue:[NSNull null] forKey:@"inputImage"];
[self setBackgroundFilters:[NSArray arrayWithObject:blur]];
}
- (void)hide {
[self setBackgroundFilters:[NSArray array]];
[self setAlphaValue:0];
}
#pragma mark -
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
NSDragOperation result;
if ([delegate respondsToSelector:@selector(dropOverlayView:validateDrop:)]) {
result = [delegate dropOverlayView:self validateDrop:sender];
} else {
result = NSDragOperationGeneric;
}
if (result != NSDragOperationNone) {
[self show];
}
return result;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender {
[self hide];
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
[self hide];
return [delegate dropOverlayView:self acceptDrop:sender];
}
@end