refactoring to common code for focus set and lost events, so that changes can be made a single place, see #14269

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76575 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2014-05-18 10:44:24 +00:00
parent 31b8c29fcd
commit 2b99f92872
2 changed files with 32 additions and 22 deletions

View File

@@ -131,6 +131,8 @@ public :
virtual bool DoHandleMouseEvent(NSEvent *event);
virtual bool DoHandleKeyEvent(NSEvent *event);
virtual bool DoHandleCharEvent(NSEvent *event, NSString *text);
virtual void DoNotifyFocusSet();
virtual void DoNotifyFocusLost();
virtual void DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow);
virtual void SetupKeyEvent(wxKeyEvent &wxevent, NSEvent * nsEvent, NSString* charString = NULL);

View File

@@ -1479,15 +1479,9 @@ bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)
bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
{
wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
// get the current focus before running becomeFirstResponder
NSView* otherView = FindFocus();
wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
BOOL r = superimpl(slf, (SEL)_cmd);
if ( r )
{
DoNotifyFocusEvent( true, otherWindow );
}
DoNotifyFocusSet();
return r;
}
@@ -1497,22 +1491,12 @@ bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd)
wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
BOOL r = superimpl(slf, (SEL)_cmd);
NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder();
NSView* otherView = wxOSXGetViewFromResponder(responder);
wxWidgetImpl* otherWindow = FindBestFromWXWidget(otherView);
// It doesn't make sense to notify about the loss of focus if it's the same
// control in the end, and just a different subview
if ( otherWindow == this )
return r;
// NSTextViews have an editor as true responder, therefore the might get the
// resign notification if their editor takes over, don't trigger any event then
// wxNSTextFields and wxNSComboBoxes have an editor as real responder, therefore they get
// a resign notification when their editor takes over, don't trigger event here, the control
// gets a controlTextDidEndEditing notification which will send a focus kill.
if ( r && !m_hasEditor)
{
DoNotifyFocusEvent( false, otherWindow );
}
DoNotifyFocusLost();
return r;
}
@@ -2785,6 +2769,30 @@ bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
return result;
}
void wxWidgetCocoaImpl::DoNotifyFocusSet()
{
NSResponder* responder = wxNonOwnedWindowCocoaImpl::GetFormerFirstResponder();
NSView* otherView = wxOSXGetViewFromResponder(responder);
wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
// It doesn't make sense to notify about the focus set if it's the same
// control in the end, and just a different subview
if ( otherWindow != this )
DoNotifyFocusEvent(true, otherWindow);
}
void wxWidgetCocoaImpl::DoNotifyFocusLost()
{
NSResponder * responder = wxNonOwnedWindowCocoaImpl::GetNextFirstResponder();
NSView* otherView = wxOSXGetViewFromResponder(responder);
wxWidgetImpl* otherWindow = FindBestFromWXWidget(otherView);
// It doesn't make sense to notify about the loss of focus if it's the same
// control in the end, and just a different subview
if ( otherWindow != this )
DoNotifyFocusEvent( false, otherWindow );
}
void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
{
wxWindow* thisWindow = GetWXPeer();