Debian Codegraph @

hiro/cocoa/widget/viewport.cpp

raw
1 #if defined(Hiro_Viewport)
2
3 @implementation CocoaViewport : NSView
4
5 -(id) initWith:(hiro::mViewport&)viewportReference {
6 if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
7 viewport = &viewportReference;
8 }
9 return self;
10 }
11
12 -(void) resetCursorRects {
13 if(auto mouseCursor = NSMakeCursor(viewport->mouseCursor())) {
14 [self addCursorRect:self.bounds cursor:mouseCursor];
15 }
16 }
17
18 -(void) drawRect:(NSRect)rect {
19 [[NSColor blackColor] setFill];
20 NSRect frame = self.bounds;
21 NSRectFillUsingOperation(frame, NSCompositingOperationSourceOver);
22 }
23
24 -(BOOL) acceptsFirstResponder {
25 return YES;
26 }
27
28 -(NSDragOperation) draggingEntered:(id<NSDraggingInfo>)sender {
29 return DropPathsOperation(sender);
30 }
31
32 -(BOOL) performDragOperation:(id<NSDraggingInfo>)sender {
33 auto paths = DropPaths(sender);
34 if(paths.empty()) return NO;
35 viewport->doDrop(paths);
36 return YES;
37 }
38
39 -(void) keyDown:(NSEvent*)event {
40 }
41
42 -(void) keyUp:(NSEvent*)event {
43 }
44
45 @end
46
47 namespace hiro {
48
49 auto pViewport::construct() -> void {
50 cocoaView = cocoaViewport = [[CocoaViewport alloc] initWith:self()];
51 pWidget::construct();
52 }
53
54 auto pViewport::destruct() -> void {
55 [cocoaView removeFromSuperview];
56 }
57
58 auto pViewport::handle() const -> uintptr_t {
59 return (uintptr_t)cocoaViewport;
60 }
61
62 auto pViewport::setDroppable(bool droppable) -> void {
63 if(droppable) {
64 [cocoaViewport registerForDraggedTypes:[NSArray arrayWithObject:NSPasteboardTypeFileURL]];
65 } else {
66 [cocoaViewport unregisterDraggedTypes];
67 }
68 }
69
70 auto pViewport::setFocusable(bool focusable) -> void {
71 //TODO
72 }
73
74 }
75
76 #endif