From: <li...@us...> - 2010-08-25 21:49:12
|
Revision: 13638 http://alleg.svn.sourceforge.net/alleg/?rev=13638&view=rev Author: lillo Date: 2010-08-25 21:49:04 +0000 (Wed, 25 Aug 2010) Log Message: ----------- Emit ALLEGRO_EVENT_NATIVE_DIALOG_CLOSE when closing log window Modified Paths: -------------- allegro/branches/4.9/addons/native_dialog/osx_dialog.m Modified: allegro/branches/4.9/addons/native_dialog/osx_dialog.m =================================================================== --- allegro/branches/4.9/addons/native_dialog/osx_dialog.m 2010-08-25 20:10:39 UTC (rev 13637) +++ allegro/branches/4.9/addons/native_dialog/osx_dialog.m 2010-08-25 21:49:04 UTC (rev 13638) @@ -155,26 +155,58 @@ } +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 +@interface LogView : NSTextView <NSWindowDelegate> +#else @interface LogView : NSTextView +#endif { + ALLEGRO_NATIVE_DIALOG *textlog; } --(void) keyDown:(NSEvent*) event; +@property ALLEGRO_NATIVE_DIALOG *textlog; +- (void)keyDown: (NSEvent*)event; +- (BOOL)windowShouldClose: (id)sender; +- (void)emitCloseEventWithKeypress: (BOOL)keypress; @end + @implementation LogView -/* Keyboard event handler */ --(void) keyDown:(NSEvent*) event +@synthesize textlog; + +- (void)keyDown: (NSEvent*)event { if (([event keyCode] == 0x35) || // Escape (([event keyCode] == 0x0D) && ([event modifierFlags] & NSCommandKeyMask))) { // Command+W [[self window] close]; + [self emitCloseEventWithKeypress: YES]; } else { [super keyDown: event]; } } +- (BOOL)windowShouldClose: (id)sender +{ + (void)sender; + if ([self textlog]->is_active) { + if (!([self textlog]->flags & ALLEGRO_TEXTLOG_NO_CLOSE)) { + [self emitCloseEventWithKeypress: NO]; + } + } + return YES; +} + +- (void)emitCloseEventWithKeypress: (BOOL)keypress +{ + ALLEGRO_EVENT event; + event.user.type = ALLEGRO_EVENT_NATIVE_DIALOG_CLOSE; + event.user.timestamp = al_current_time(); + event.user.data1 = (intptr_t)[self textlog]; + event.user.data2 = (intptr_t)keypress; + al_emit_user_event(&[self textlog]->tl_events, &event, NULL); +} + @end @@ -217,6 +249,7 @@ rect = [[scrollView contentView] frame]; LogView *view = [[LogView alloc] initWithFrame: rect]; + [view setTextlog: textlog]; [view setHorizontallyResizable: YES]; [view setVerticallyResizable: YES]; [view setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; @@ -230,6 +263,7 @@ [[win contentView] addSubview: scrollView]; + [win setDelegate: view]; [win orderFront: nil]; /* Save handles for future use. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |