From a23f3c57caa37886956b704cb232ef211792c1aa Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sun, 4 Feb 2018 11:42:54 -0500 Subject: Add Quit menu item to gfcocoa --- bin/gfcocoa.m | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'bin/gfcocoa.m') 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]; -- cgit 1.4.1 freecell.6?id=6f35229b87e64472805ba83e70bac5d8f90cb3e0&follow=1'>Collapse)Author 15 hoursPut lens and (future) film at the tops of photo pagesJune McEnroe 2024-05-22Remove use of sysexits.hJune McEnroe 2024-05-22Add photo descriptions from 05-03 and 05-06June McEnroe 2024-05-21Fix = precedence in whenJune McEnroe