diff options
author | June McEnroe <programble@gmail.com> | 2018-02-04 11:42:54 -0500 |
---|---|---|
committer | June McEnroe <programble@gmail.com> | 2018-02-04 11:42:54 -0500 |
commit | a23f3c57caa37886956b704cb232ef211792c1aa (patch) | |
tree | 07c5b66803e59231b0d3a37ebb8174aadeeb7bb4 /bin | |
parent | Switch back to sane Objective-C style (diff) | |
download | src-a23f3c57caa37886956b704cb232ef211792c1aa.tar.gz src-a23f3c57caa37886956b704cb232ef211792c1aa.zip |
Add Quit menu item to gfcocoa
Diffstat (limited to '')
-rw-r--r-- | bin/gfcocoa.m | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/bin/gfcocoa.m b/bin/gfcocoa.m index 720f1c72..b1118bf3 100644 --- a/bin/gfcocoa.m +++ b/bin/gfcocoa.m @@ -61,19 +61,21 @@ static uint32_t buf[WIDTH * HEIGHT]; - (void) keyDown: (NSEvent *) event { char in; - [ + BOOL converted = [ [event characters] getBytes: &in maxLength: 1 usedLength: NULL encoding: NSASCIIStringEncoding - options: NSStringEncodingConversionAllowLossy + options: 0 range: NSMakeRange(0, 1) remainingRange: NULL ]; - input(in); - draw(buf, WIDTH, HEIGHT); - [self setNeedsDisplay: YES]; + if (converted) { + input(in); + draw(buf, WIDTH, HEIGHT); + [self setNeedsDisplay: YES]; + } } @end @@ -90,25 +92,43 @@ int main(int argc, char *argv[]) { int error = init(argc, argv); if (error) return error; - draw(buf, WIDTH, HEIGHT); - [NSApplication sharedApplication]; [NSApp setActivationPolicy: NSApplicationActivationPolicyRegular]; [NSApp setDelegate: [Delegate new]]; + NSString *name = [[NSProcessInfo processInfo] processName]; + NSMenu *menu = [NSMenu new]; + NSMenuItem *quit = [ + [NSMenuItem alloc] + initWithTitle: [@"Quit " stringByAppendingString: name] + action: @selector(terminate:) + keyEquivalent: @"q" + ]; + [menu addItem: quit]; + NSMenuItem *menuItem = [NSMenuItem new]; + [menuItem setSubmenu: menu]; + [NSApp setMainMenu: [NSMenu new]]; + [[NSApp mainMenu] addItem: menuItem]; + + NSUInteger style = NSTitledWindowMask + | NSClosableWindowMask + | NSMiniaturizableWindowMask + | NSResizableWindowMask; NSWindow *window = [ [NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, WIDTH, HEIGHT) - styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask + styleMask: style backing: NSBackingStoreBuffered defer: YES ]; + [window setTitle: name]; + [window center]; BufferView *view = [[BufferView alloc] initWithFrame: [window frame]]; [window setContentView: view]; - [window setTitle: [NSString stringWithUTF8String: argv[0]]]; - [window center]; + draw(buf, WIDTH, HEIGHT); + [window makeKeyAndOrderFront: nil]; [NSApp activateIgnoringOtherApps: YES]; [NSApp run]; |