diff --git a/include/wx/cocoa/NSWindow.h b/include/wx/cocoa/NSWindow.h index 8f73ba3267..06d7aebf6c 100644 --- a/include/wx/cocoa/NSWindow.h +++ b/include/wx/cocoa/NSWindow.h @@ -25,9 +25,13 @@ public: void AssociateNSWindow(WX_NSWindow cocoaNSWindow); void DisassociateNSWindow(WX_NSWindow cocoaNSWindow); virtual void Cocoa_close(void) = 0; + virtual bool Cocoa_canBecomeMainWindow(bool &canBecome) + { return false; } virtual bool CocoaDelegate_windowShouldClose(void) = 0; virtual void CocoaDelegate_windowDidBecomeKey(void) { } virtual void CocoaDelegate_windowDidResignKey(void) { } + virtual void CocoaDelegate_windowDidBecomeMain(void) { } + virtual void CocoaDelegate_windowDidResignMain(void) { } protected: static struct objc_object *sm_cocoaDelegate; }; diff --git a/src/cocoa/NSWindow.mm b/src/cocoa/NSWindow.mm index 45cf2bfa0a..e3c1446d78 100644 --- a/src/cocoa/NSWindow.mm +++ b/src/cocoa/NSWindow.mm @@ -39,6 +39,8 @@ - (void)windowDidBecomeKey: (NSNotification *)notification; - (void)windowDidResignKey: (NSNotification *)notification; +- (void)windowDidBecomeMain: (NSNotification *)notification; +- (void)windowDidResignMain: (NSNotification *)notification; - (BOOL)windowShouldClose: (id)sender; @end //interface wxNSWindowDelegate @@ -58,6 +60,20 @@ win->CocoaDelegate_windowDidResignKey(); } +- (void)windowDidBecomeMain: (NSNotification *)notification +{ + wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]); + wxCHECK_RET(win,"notificationDidBecomeMain received but no wxWindow exists"); + win->CocoaDelegate_windowDidBecomeMain(); +} + +- (void)windowDidResignMain: (NSNotification *)notification +{ + wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]); + wxCHECK_RET(win,"notificationDidResignMain received but no wxWindow exists"); + win->CocoaDelegate_windowDidResignMain(); +} + - (BOOL)windowShouldClose: (id)sender { wxLogDebug("windowShouldClose"); @@ -108,6 +124,7 @@ void wxCocoaNSWindow::DisassociateNSWindow(WX_NSWindow cocoaNSWindow) } - (void)close; +- (BOOL)canBecomeMainWindow; @end // wxPoserNSwindow WX_IMPLEMENT_POSER(wxPoserNSWindow); @@ -122,5 +139,14 @@ WX_IMPLEMENT_POSER(wxPoserNSWindow); [super close]; } +- (BOOL)canBecomeMainWindow +{ + bool canBecome = false; + wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self); + if(!tlw || !tlw->Cocoa_canBecomeMainWindow(canBecome)) + canBecome = [super canBecomeMainWindow]; + return canBecome; +} + @end // implementation wxPoserNSWindow