-
Notifications
You must be signed in to change notification settings - Fork 8
/
DropFileView.m
executable file
·140 lines (112 loc) · 3.23 KB
/
DropFileView.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// MGDropFileView.m
// WhatSub
//
// Created by Marcin Grabda on 5/8/09.
// Copyright 2010 Marcin Grabda. All rights reserved.
//
#import "DropFileView.h"
#import "AppController.h"
@implementation DropFileView
@synthesize filenames;
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
NSString* pboardType = NSFilenamesPboardType;
NSArray* dragTypes = [NSArray arrayWithObjects:pboardType,nil];
[self registerForDraggedTypes:dragTypes];
}
return self;
}
- (void)drawRect:(NSRect)rect
{
[self drawCenteredAndRoundedRect];
[self drawCenteredText];
[self drawCenteredArrow];
}
- (void)drawCenteredText
{
NSRect rect = NSMakeRect(110, 0, 150, 50);
NSDictionary* attrs = [NSMutableDictionary dictionary];
NSFont* font = [NSFont fontWithName:@"Lucida Grande Bold" size:18];
NSColor* color = [NSColor grayColor];
[attrs setValue:font forKey:NSFontAttributeName];
[attrs setValue:color forKey:NSForegroundColorAttributeName];
[@"Drop File Here" drawInRect:rect withAttributes:attrs];
}
- (void)drawCenteredAndRoundedRect
{
NSRect rect = NSMakeRect(147, 70, 60, 60);
NSColor* grayColor = [NSColor lightGrayColor];
[grayColor set];
NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:rect
xRadius:10
yRadius:10];
[path setLineWidth:2];
CGFloat a[2]; a[0]=13.0; a[1]=4.0;
[path setLineDash: a
count: 2
phase: 0.0];
[path stroke];
}
- (void)drawCenteredArrow
{
NSPoint point1 = NSMakePoint(165, 100);
NSPoint point2 = NSMakePoint(177.5, 87);
NSPoint point3 = NSMakePoint(190, 100);
NSPoint point4 = NSMakePoint(181, 100);
NSPoint point5 = NSMakePoint(181, 113);
NSPoint point6 = NSMakePoint(174, 113);
NSPoint point7 = NSMakePoint(174, 100);
NSBezierPath* triangle = [NSBezierPath bezierPath];
[triangle moveToPoint:point1];
[triangle lineToPoint:point2];
[triangle lineToPoint:point3];
[triangle lineToPoint:point4];
[triangle lineToPoint:point5];
[triangle lineToPoint:point6];
[triangle lineToPoint:point7];
[triangle lineToPoint:point1];
NSColor* grayColor = [NSColor lightGrayColor];
[grayColor set];
[triangle stroke];
[triangle fill];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] )
{
[self setNeedsDisplay:YES];
return NSDragOperationCopy;
}
return NSDragOperationNone;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
[self setNeedsDisplay:YES];
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
self.filenames = files;
AppController* appController = [NSApp delegate];
[appController filesDragged:self];
}
return YES;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
[self setNeedsDisplay:YES];
}
@end