From 67d2dac82e90703185d97fd56a43a917c9b82c81 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Tue, 11 Jan 2005 03:21:31 +0000 Subject: [PATCH] Replaced obviously incorrect code for SetFocus and DoFindFocus. Effectively reverts revision 1.53. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31313 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/cocoa/window.mm | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/cocoa/window.mm b/src/cocoa/window.mm index f82db09e00..00f89e22d1 100644 --- a/src/cocoa/window.mm +++ b/src/cocoa/window.mm @@ -25,6 +25,8 @@ #import #import #import +#import +#import // Turn this on to paint green over the dummy views for debugging #undef WXCOCOA_FILL_DUMMY_VIEW @@ -706,14 +708,8 @@ void wxWindow::Refresh(bool eraseBack, const wxRect *rect) void wxWindow::SetFocus() { -#ifdef __WXDEBUG__ - bool bOK = -#endif - [GetNSView() lockFocusIfCanDraw]; - - //Note that the normal lockFocus works on hidden and minimized windows - //and has no return value - which probably isn't what we want - wxASSERT(bOK); + if([GetNSView() acceptsFirstResponder]) + [[GetNSView() window] makeFirstResponder: GetNSView()]; } void wxWindow::DoCaptureMouse() @@ -894,12 +890,30 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) // Get the window with the focus wxWindow *wxWindowBase::DoFindFocus() { - wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa([NSView focusView]); - - if (!win) + // Basically we are somewhat emulating the responder chain here except + // we are only loking for the first responder in the key window or + // upon failing to find one if the main window is different we look + // for the first responder in the main window. + + // Note that the firstResponder doesn't necessarily have to be an + // NSView but wxCocoaNSView::GetFromCocoa() will simply return + // NULL unless it finds its argument in its hash map. + + wxCocoaNSView *win; + + NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow]; + win = wxCocoaNSView::GetFromCocoa([keyWindow firstResponder]); + if(win) + return win->GetWxWindow(); + + NSWindow *mainWindow = [[NSApplication sharedApplication] keyWindow]; + if(mainWindow == keyWindow) return NULL; - - return win->GetWxWindow(); + win = wxCocoaNSView::GetFromCocoa([mainWindow firstResponder]); + if(win) + return win->GetWxWindow(); + + return NULL; } /* static */ wxWindow *wxWindowBase::GetCapture() -- 2.47.2