2019-01-28 19:46:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/sk_app/Application.h"
|
|
|
|
#include "tools/sk_app/mac/Window_mac.h"
|
2019-01-28 19:46:04 +00:00
|
|
|
|
|
|
|
@interface AppDelegate : NSObject<NSApplicationDelegate, NSWindowDelegate>
|
|
|
|
|
|
|
|
@property (nonatomic, assign) BOOL done;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AppDelegate : NSObject
|
|
|
|
|
|
|
|
@synthesize done = _done;
|
|
|
|
|
|
|
|
- (id)init {
|
|
|
|
self = [super init];
|
|
|
|
_done = FALSE;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
|
|
|
|
_done = TRUE;
|
|
|
|
return NSTerminateCancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
|
|
|
|
[NSApp stop:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
using sk_app::Application;
|
2019-02-08 18:44:42 +00:00
|
|
|
using sk_app::Window_mac;
|
2019-01-28 19:46:04 +00:00
|
|
|
|
|
|
|
int main(int argc, char * argv[]) {
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
|
|
|
|
// we only run on systems that support at least Core Profile 3.2
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
[NSApplication sharedApplication];
|
|
|
|
|
|
|
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
|
|
|
|
|
|
|
//Create the application menu.
|
|
|
|
NSMenu* menuBar=[[NSMenu alloc] initWithTitle:@"AMainMenu"];
|
2019-05-16 14:31:56 +00:00
|
|
|
[NSApp setMainMenu:menuBar];
|
2019-01-28 19:46:04 +00:00
|
|
|
|
|
|
|
NSMenuItem* item;
|
|
|
|
NSMenu* subMenu;
|
|
|
|
|
2020-08-14 14:52:06 +00:00
|
|
|
item=[[NSMenuItem alloc] initWithTitle:@"Apple" action:nil keyEquivalent:@""];
|
2019-01-28 19:46:04 +00:00
|
|
|
[menuBar addItem:item];
|
|
|
|
subMenu=[[NSMenu alloc] initWithTitle:@"Apple"];
|
|
|
|
[menuBar setSubmenu:subMenu forItem:item];
|
|
|
|
[item release];
|
|
|
|
item=[[NSMenuItem alloc] initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"];
|
|
|
|
[subMenu addItem:item];
|
|
|
|
[item release];
|
|
|
|
[subMenu release];
|
|
|
|
|
|
|
|
// Set AppDelegate to catch certain global events
|
2019-05-16 14:31:56 +00:00
|
|
|
AppDelegate* appDelegate = [[AppDelegate alloc] init];
|
2019-01-28 19:46:04 +00:00
|
|
|
[NSApp setDelegate:appDelegate];
|
|
|
|
|
2019-06-21 15:06:08 +00:00
|
|
|
Application* app = Application::Create(argc, argv, nullptr);
|
|
|
|
|
2019-01-28 19:46:04 +00:00
|
|
|
// This will run until the application finishes launching, then lets us take over
|
|
|
|
[NSApp run];
|
|
|
|
|
|
|
|
// Now we process the events
|
|
|
|
while (![appDelegate done]) {
|
|
|
|
NSEvent* event;
|
|
|
|
do {
|
|
|
|
event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
|
|
|
untilDate:[NSDate distantPast]
|
|
|
|
inMode:NSDefaultRunLoopMode
|
|
|
|
dequeue:YES];
|
|
|
|
[NSApp sendEvent:event];
|
|
|
|
} while (event != nil);
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
[pool drain];
|
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
// Rather than depending on a Mac event to drive this, we treat our window
|
|
|
|
// invalidation flag as a separate event stream. Window::onPaint() will clear
|
|
|
|
// the invalidation flag, effectively removing it from the stream.
|
|
|
|
Window_mac::PaintWindows();
|
|
|
|
|
2019-01-28 19:46:04 +00:00
|
|
|
app->onIdle();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete app;
|
|
|
|
|
2019-05-16 14:31:56 +00:00
|
|
|
[NSApp setDelegate:nil];
|
|
|
|
[appDelegate release];
|
|
|
|
|
2019-01-28 19:46:04 +00:00
|
|
|
[menuBar release];
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|