2013-03-15 13:11:33 +00:00
|
|
|
@implementation CocoaDelegate : NSObject
|
|
|
|
|
2013-03-21 12:59:01 +00:00
|
|
|
-(NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender {
|
2013-03-15 13:11:33 +00:00
|
|
|
using phoenix::Application;
|
|
|
|
if(Application::Cocoa::onQuit) Application::Cocoa::onQuit();
|
|
|
|
else Application::quit();
|
|
|
|
return NSTerminateCancel;
|
|
|
|
}
|
|
|
|
|
2013-03-21 12:59:01 +00:00
|
|
|
-(BOOL) applicationShouldHandleReopen:(NSApplication*)application hasVisibleWindows:(BOOL)flag {
|
|
|
|
using phoenix::Application;
|
|
|
|
if(Application::Cocoa::onActivate) Application::Cocoa::onActivate();
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) run:(NSTimer*)timer {
|
2013-03-15 13:11:33 +00:00
|
|
|
using phoenix::Application;
|
|
|
|
if(Application::main) Application::main();
|
|
|
|
}
|
|
|
|
|
2013-04-09 13:31:46 +00:00
|
|
|
-(void) updateInDock:(NSTimer*)timer {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSArray* windows = [NSApp windows];
|
2013-04-09 13:31:46 +00:00
|
|
|
for(unsigned n = 0; n < [windows count]; n++) {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSWindow* window = [windows objectAtIndex:n];
|
2013-04-09 13:31:46 +00:00
|
|
|
if([window isMiniaturized]) {
|
|
|
|
[window updateInDock];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
@end
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
CocoaDelegate* cocoaDelegate = nullptr;
|
2013-03-15 13:11:33 +00:00
|
|
|
|
|
|
|
namespace phoenix {
|
|
|
|
|
|
|
|
void pApplication::run() {
|
2013-05-02 11:25:45 +00:00
|
|
|
//NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:0.1667 target:cocoaDelegate selector:@selector(updateInDock:) userInfo:nil repeats:YES];
|
2013-04-09 13:31:46 +00:00
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
if(Application::main) {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:cocoaDelegate selector:@selector(run:) userInfo:nil repeats:YES];
|
2013-03-21 12:59:01 +00:00
|
|
|
|
|
|
|
//below line is needed to run application during window resize; however it has a large performance penalty on the resize smoothness
|
|
|
|
//[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode];
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
2013-04-09 13:31:46 +00:00
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
[NSApp run];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool pApplication::pendingEvents() {
|
|
|
|
bool result = false;
|
|
|
|
@autoreleasepool {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:NO];
|
2013-03-15 13:11:33 +00:00
|
|
|
if(event != nil) result = true;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pApplication::processEvents() {
|
|
|
|
@autoreleasepool {
|
|
|
|
while(applicationState.quit == false) {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
|
2013-03-15 13:11:33 +00:00
|
|
|
if(event == nil) break;
|
|
|
|
[event retain];
|
|
|
|
[NSApp sendEvent:event];
|
|
|
|
[event release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pApplication::quit() {
|
|
|
|
@autoreleasepool {
|
|
|
|
[NSApp stop:nil];
|
2013-05-02 11:25:45 +00:00
|
|
|
NSEvent* event = [NSEvent otherEventWithType:NSApplicationDefined location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0.0 windowNumber:0 context:nil subtype:0 data1:0 data2:0];
|
2013-03-15 13:11:33 +00:00
|
|
|
[NSApp postEvent:event atStart:true];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pApplication::initialize() {
|
|
|
|
@autoreleasepool {
|
|
|
|
[NSApplication sharedApplication];
|
|
|
|
cocoaDelegate = [[CocoaDelegate alloc] init];
|
|
|
|
[NSApp setDelegate:cocoaDelegate];
|
|
|
|
//every window has the default application menu; call this so it is displayed at startup
|
2013-11-28 10:29:01 +00:00
|
|
|
[NSApp setMainMenu:[pWindow::none().p.cocoaWindow menu]];
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|