| 1 |
@implementation CocoaViewport : NSView |
| 2 |
|
| 3 |
-(id) initWith:(phoenix::Viewport&)viewportReference { |
| 4 |
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) { |
| 5 |
viewport = &viewportReference; |
| 6 |
} |
| 7 |
return self; |
| 8 |
} |
| 9 |
|
| 10 |
-(void) drawRect:(NSRect)rect { |
| 11 |
[[NSColor blackColor] setFill]; |
| 12 |
NSRectFillUsingOperation(rect, NSCompositeSourceOver); |
| 13 |
} |
| 14 |
|
| 15 |
-(BOOL) acceptsFirstResponder { |
| 16 |
return YES; |
| 17 |
} |
| 18 |
|
| 19 |
-(NSDragOperation) draggingEntered:(id<NSDraggingInfo>)sender { |
| 20 |
return DropPathsOperation(sender); |
| 21 |
} |
| 22 |
|
| 23 |
-(BOOL) performDragOperation:(id<NSDraggingInfo>)sender { |
| 24 |
lstring paths = DropPaths(sender); |
| 25 |
if(paths.empty()) return NO; |
| 26 |
if(viewport->onDrop) viewport->onDrop(paths); |
| 27 |
return YES; |
| 28 |
} |
| 29 |
|
| 30 |
-(void) keyDown:(NSEvent*)event { |
| 31 |
} |
| 32 |
|
| 33 |
-(void) keyUp:(NSEvent*)event { |
| 34 |
} |
| 35 |
|
| 36 |
@end |
| 37 |
|
| 38 |
namespace phoenix { |
| 39 |
|
| 40 |
uintptr_t pViewport::handle() { |
| 41 |
return (uintptr_t)cocoaViewport; |
| 42 |
} |
| 43 |
|
| 44 |
void pViewport::setDroppable(bool droppable) { |
| 45 |
@autoreleasepool { |
| 46 |
if(droppable) { |
| 47 |
[cocoaViewport registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]]; |
| 48 |
} else { |
| 49 |
[cocoaViewport unregisterDraggedTypes]; |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
void pViewport::constructor() { |
| 55 |
@autoreleasepool { |
| 56 |
cocoaView = cocoaViewport = [[CocoaViewport alloc] initWith:viewport]; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
void pViewport::destructor() { |
| 61 |
@autoreleasepool { |
| 62 |
[cocoaView release]; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
} |