Last active
August 29, 2015 14:00
-
-
Save tonyarnold/11361553 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by Tony Arnold on 4/03/2014. | |
// Copyright (c) 2014 The CocoaBots. All rights reserved. | |
// | |
#import <Cocoa/Cocoa.h> | |
@interface NSView (TCBAdditions) | |
- (void)tcb_setDraggingDestinationDelegate:(id<NSDraggingDestination>)delegate; | |
- (id<NSDraggingDestination>)tcb_draggingDestinationDelegate; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by Tony Arnold on 4/03/2014. | |
// Copyright (c) 2014 The CocoaBots. All rights reserved. | |
// | |
#import "NSView+TCBAdditions.h" | |
#import <objc/runtime.h> | |
@implementation NSView (TCBAdditions) | |
- (void)tcb_setDraggingDestinationDelegate:(id<NSDraggingDestination>)delegate | |
{ | |
objc_setAssociatedObject(self, @selector(tcb_draggingDestinationDelegate), delegate, OBJC_ASSOCIATION_ASSIGN); | |
} | |
- (id<NSDraggingDestination>)tcb_draggingDestinationDelegate | |
{ | |
return objc_getAssociatedObject(self, @selector(tcb_draggingDestinationDelegate)); | |
} | |
#pragma mark - NSDraggingDestination | |
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender | |
{ | |
id<NSDraggingDestination> delegate = [self tcb_draggingDestinationDelegate]; | |
if ([delegate respondsToSelector:_cmd]) { | |
return [delegate draggingEntered:sender]; | |
} | |
return NSDragOperationNone; | |
} | |
- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender | |
{ | |
id<NSDraggingDestination> delegate = [self tcb_draggingDestinationDelegate]; | |
if ([delegate respondsToSelector:_cmd]) { | |
return [delegate draggingUpdated:sender]; | |
} | |
return NSDragOperationNone; | |
} | |
- (void)draggingExited:(id<NSDraggingInfo>)sender | |
{ | |
id<NSDraggingDestination> delegate = [self tcb_draggingDestinationDelegate]; | |
if ([delegate respondsToSelector:_cmd]) { | |
[delegate draggingExited:sender]; | |
} | |
} | |
- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender | |
{ | |
id<NSDraggingDestination> delegate = [self tcb_draggingDestinationDelegate]; | |
if ([delegate respondsToSelector:_cmd]) { | |
return [delegate prepareForDragOperation:sender]; | |
} | |
return NO; | |
} | |
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender | |
{ | |
id<NSDraggingDestination> delegate = [self tcb_draggingDestinationDelegate]; | |
if ([delegate respondsToSelector:_cmd]) { | |
return [delegate performDragOperation:sender]; | |
} | |
return NO; | |
} | |
- (void)concludeDragOperation:(id<NSDraggingInfo>)sender | |
{ | |
id<NSDraggingDestination> delegate = [self tcb_draggingDestinationDelegate]; | |
if ([delegate respondsToSelector:_cmd]) { | |
[delegate concludeDragOperation:sender]; | |
} | |
} | |
- (void)draggingEnded:(id<NSDraggingInfo>)sender | |
{ | |
id<NSDraggingDestination> delegate = [self tcb_draggingDestinationDelegate]; | |
if ([delegate respondsToSelector:_cmd]) { | |
[delegate draggingEnded:sender]; | |
} | |
} | |
- (BOOL)wantsPeriodicDraggingUpdates | |
{ | |
id<NSDraggingDestination> delegate = [self tcb_draggingDestinationDelegate]; | |
if ([delegate respondsToSelector:_cmd]) { | |
return [delegate wantsPeriodicDraggingUpdates]; | |
} | |
return NO; | |
} | |
- (void)updateDraggingItemsForDrag:(id<NSDraggingInfo>)sender | |
{ | |
id<NSDraggingDestination> delegate = [self tcb_draggingDestinationDelegate]; | |
if ([delegate respondsToSelector:_cmd]) { | |
[delegate updateDraggingItemsForDrag:sender]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment