Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/CrossWindow/Cocoa/CocoaEventQueue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,23 @@
break;
case NSEventTypeScrollWheel:
[nsEvent deltaY];

break;

case NSEventTypeApplicationDefined:
switch((EventType) nsEvent.subtype) {
case EventType::Close: {
curEvent = xwin::Event(EventType::Close);
} break;
case EventType::Resize: {
curEvent = xwin::Event(xwin::ResizeData(nsEvent.data1, nsEvent.data2, true));
} break;
case EventType::Focus: {
curEvent = xwin::Event(xwin::FocusData(nsEvent.data1 ? true : false));
} break;
default: {

} break;
}
break;
default:
break;
Expand Down
3 changes: 3 additions & 0 deletions src/CrossWindow/Cocoa/CocoaWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class Window
// XWinWindow*
void* window;

// XWinWindowDelegate*
void* windowDelegate;

// XWinView*
void* view;

Expand Down
61 changes: 61 additions & 0 deletions src/CrossWindow/Cocoa/CocoaWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,60 @@ @implementation XWinWindow

@end

@interface XWinWindowDelegate : NSObject <NSWindowDelegate>
{
}

@property (assign) XWinWindow* window;

-(void) postEvent: (xwin::EventType)type data1:(NSInteger)data1 data2:(NSInteger)data2;

@end

@implementation XWinWindowDelegate

- (void) postEvent:(xwin::EventType)type data1:(NSInteger)data1 data2:(NSInteger)data2
{
NSPoint point;
NSTimeInterval timestamp;
NSEvent* event = [NSEvent
otherEventWithType:NSEventTypeApplicationDefined
location:point
modifierFlags:0
timestamp:timestamp
windowNumber:self.window.windowNumber
context:nil
subtype:(short) type
data1:data1
data2:data2
];
[self.window postEvent:event atStart:false];
}

- (void)windowDidBecomeMain:(NSNotification *)notification
{
[self postEvent: xwin::EventType::Focus data1: 1 data2: 0];
}

- (void)windowDidResignMain:(NSNotification *)notification
{
[self postEvent: xwin::EventType::Focus data1: 0 data2: 0];
}

- (void)windowWillClose:(NSNotification *)notification
{
[self postEvent: xwin::EventType::Close data1: 0 data2: 0];
}

- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize
{
CGSize contentSize = [[self.window contentView] frame].size;
[self postEvent: xwin::EventType::Resize data1: contentSize.width data2: contentSize.height];
return frameSize;
}

@end

@interface XWinView : NSView
- (BOOL) acceptsFirstResponder;
- (BOOL) isOpaque;
Expand Down Expand Up @@ -118,6 +172,13 @@ - (BOOL)isOpaque
mTitle = [NSString stringWithCString:desc.title.c_str()
encoding:[NSString defaultCStringEncoding]];
XWinWindow* w = ((XWinWindow*)window);

// Setup NSWindowDelegate
windowDelegate = [XWinWindowDelegate alloc];
XWinWindowDelegate* wd = ((XWinWindowDelegate*)windowDelegate);
[w setDelegate: wd];
[wd setWindow: w];

if(!desc.title.empty())
{ [w setTitle: (NSString*)mTitle]; }
if(desc.centered)
Expand Down