1/* 2* Copyright 2019 Google Inc. 3* 4* Use of this source code is governed by a BSD-style license that can be 5* found in the LICENSE file. 6*/ 7 8#import <Cocoa/Cocoa.h> 9 10#include "../Application.h" 11 12@interface AppDelegate : NSObject<NSApplicationDelegate, NSWindowDelegate> 13 14@property (nonatomic, assign) BOOL done; 15 16@end 17 18@implementation AppDelegate : NSObject 19 20@synthesize done = _done; 21 22- (id)init { 23 self = [super init]; 24 _done = FALSE; 25 return self; 26} 27 28- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { 29 _done = TRUE; 30 return NSTerminateCancel; 31} 32 33- (void)applicationDidFinishLaunching:(NSNotification *)notification { 34 [NSApp stop:nil]; 35} 36 37@end 38 39/////////////////////////////////////////////////////////////////////////////////////////// 40 41using sk_app::Application; 42 43int main(int argc, char * argv[]) { 44#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070 45 // we only run on systems that support at least Core Profile 3.2 46 return EXIT_FAILURE; 47#endif 48 49 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 50 [NSApplication sharedApplication]; 51 52 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; 53 54 //Create the application menu. 55 NSMenu* menuBar=[[NSMenu alloc] initWithTitle:@"AMainMenu"]; 56 [NSApp setMenu:menuBar]; 57 58 NSMenuItem* item; 59 NSMenu* subMenu; 60 61 item=[[NSMenuItem alloc] initWithTitle:@"Apple" action:NULL keyEquivalent:@""]; 62 [menuBar addItem:item]; 63 subMenu=[[NSMenu alloc] initWithTitle:@"Apple"]; 64 [menuBar setSubmenu:subMenu forItem:item]; 65 [item release]; 66 item=[[NSMenuItem alloc] initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"]; 67 [subMenu addItem:item]; 68 [item release]; 69 [subMenu release]; 70 71 // Set AppDelegate to catch certain global events 72 AppDelegate* appDelegate = [[[AppDelegate alloc] init] autorelease]; 73 [NSApp setDelegate:appDelegate]; 74 75 Application* app = Application::Create(argc, argv, nullptr); 76 77 // This will run until the application finishes launching, then lets us take over 78 [NSApp run]; 79 80 // Now we process the events 81 while (![appDelegate done]) { 82 NSEvent* event; 83 do { 84 event = [NSApp nextEventMatchingMask:NSAnyEventMask 85 untilDate:[NSDate distantPast] 86 inMode:NSDefaultRunLoopMode 87 dequeue:YES]; 88 [NSApp sendEvent:event]; 89 } while (event != nil); 90 91 app->onIdle(); 92 } 93 94 delete app; 95 96 [menuBar release]; 97 [pool release]; 98 99 return EXIT_SUCCESS; 100} 101